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

S3 putObject does not set Content-Type #1203

Open
martinssipenko opened this issue Mar 16, 2022 · 1 comment
Open

S3 putObject does not set Content-Type #1203

martinssipenko opened this issue Mar 16, 2022 · 1 comment

Comments

@martinssipenko
Copy link
Contributor

In contrast to the official AWS SDK Async AWS does not set content type when uploading files to S3, is this by design?

@jderusse
Copy link
Member

I noticed this few weeks ago.
I do believe, this is not the responsibility of the SDK to arbitrary change attributes.
This could be added in the SimpleS3Client. But should be left empty (and let the app decide the right ContentType)

Here is my code:

use Symfony\Component\Mime\MimeTypes;

$mimeType = new MimeTypes();

$responses[] = $this->s3Client->putObject([
  'Bucket' => $this->bucket,
  'Key' => $file->getRelativePathname()
  'Body' => fopen($file->getRealPath(), 'rb'),
  'ACL' => 'public-read',
  'CacheControl' => 'max-age=31536000',
  'ContentType' => $mimeType->getMimeTypes($file->getExtension())[0] ?? $mimeType->guessMimeType($file->getRealPath()) ?? 'application/octet-stream',
]);

note: I also noticed that AWS has a bug when uploading the object in multiparts (big objects). In such situations, AWS automatically adds empty ContentEncoding attributes, which breaks clients (like chrome/firefox browsers).
You need to disable chunk uploads via the configuration sendChunkedBody=false.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants