set content-type when uploading image

This commit is contained in:
EGOIST 2022-05-06 22:12:03 +08:00
parent 2ee4f3197d
commit bfbbf4836b
2 changed files with 4 additions and 2 deletions

View File

@ -25,13 +25,15 @@ export const s3 = singleton("s3-client", () => {
export const s3uploadFile = async (
filename: string,
file: PutObjectRequest["Body"] | string | Buffer
file: PutObjectRequest["Body"] | string | Buffer,
contentType?: string
) => {
await s3.send(
new PutObjectCommand({
Bucket: S3_BUCKET_NAME,
Key: filename,
Body: file,
ContentType: contentType,
})
)
}

View File

@ -20,7 +20,7 @@ export const action: ActionFunction = async ({ request }) => {
}
const buffer = Buffer.concat(chunks)
const filename = `${user.id}/${nanoid()}.jpg`
await s3uploadFile(filename, buffer)
await s3uploadFile(filename, buffer, "image/jpeg")
return filename
}
const formData = await unstable_parseMultipartFormData(request, uploadHandler)