Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add ContentType to headers sent to AWS S3 #4395

Open
wants to merge 3 commits into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 5 additions & 0 deletions .changeset/sixty-lobsters-appear.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
'next-tinacms-s3': minor
---

Populate ContentType in the Headers sent to s3
20 changes: 12 additions & 8 deletions packages/next-tinacms-s3/src/handlers.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,21 +3,21 @@
*/

import {
_Object,
S3Client,
S3ClientConfig,
DeleteObjectCommand,
DeleteObjectCommandInput,
ListObjectsCommand,
ListObjectsCommandInput,
PutObjectCommand,
PutObjectCommandInput,
DeleteObjectCommand,
DeleteObjectCommandInput,
S3Client,
S3ClientConfig,
_Object,
} from '@aws-sdk/client-s3'
import { Media, MediaListOptions } from 'tinacms'
import path from 'path'
import fs from 'fs'
import { NextApiRequest, NextApiResponse } from 'next'
import multer from 'multer'
import { NextApiRequest, NextApiResponse } from 'next'
import path from 'path'
import { Media, MediaListOptions } from 'tinacms'
import { promisify } from 'util'

export interface S3Config {
Expand Down Expand Up @@ -111,6 +111,9 @@ async function uploadMedia(
// eslint-disable-next-line @typescript-eslint/ban-ts-comment
// @ts-ignore
const filePath = req.file.path
// eslint-disable-next-line @typescript-eslint/ban-ts-comment
// @ts-ignore
const fileType = req.file.mimetype
const blob = fs.readFileSync(filePath)
const filename = path.basename(filePath)
const params: PutObjectCommandInput = {
Expand All @@ -120,6 +123,7 @@ async function uploadMedia(
: prefix + filename,
Body: blob,
ACL: 'public-read',
ContentType: fileType || 'application/octet-stream',
}
const command = new PutObjectCommand(params)
try {
Expand Down
Loading