Services
AWS S3
Installation
Install S3 service
npm i @uplo/service-s3Add service to Uplo
import { createS3Service } from '@uplo/service-s3'
const uplo = createUplo({
services: {
s3: createS3Service({
isPublic: false,
region: process.env.AWS_REGION,
bucket: process.env.AWS_BUCKET,
accessKeyId: '*****',
secretAccessKey: '*****',
}),
},
})Options
bucket(required): Your bucket name where to store objects.accessKeyId(required): Provide Access Key ID from your service credentialssecretAccessKey(required): Provide Secret Access Key from your service credentialsregion = 'us-east-1: Provide your service regionisPublic = false: Specify a bucket ACLendpoint: You can provide a custom endpoint if you have a custom servicepublicUrl: Base URL for public files (e.g. CDN or custom domain). Defaults to the bucket URLacl = true: Send object ACL on uploads. Setfalsefor providers without ACL supportrequestChecksumCalculation = 'WHEN_REQUIRED',responseChecksumValidation = 'WHEN_REQUIRED': AWS SDK checksum behavior. The SDK default (WHEN_SUPPORTED) signs a checksum of an empty body into direct upload URLs, so uploads failstoragePath: Default file path in the bucket for attachments without their ownstoragePath. See Storage path
Direct Upload
CORS
This is example CORS configuration for direct uploads.
[
{
"AllowedHeaders": ["*"],
"AllowedMethods": ["PUT"],
"AllowedOrigins": ["https://www.example.com"],
"ExposeHeaders": ["Origin", "Content-Type", "Content-MD5", "Content-Disposition"],
"MaxAgeSeconds": 3600
}
]Permissions
Before attaching a direct upload, Uplo reads the file with a HEAD request,
which needs s3:GetObject. Without s3:ListBucket, S3 answers 403 instead of
404 for a missing file, so the attach fails with an access error instead of
BlobNotUploadedError.