Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How can i change AWS S3 content type only for audio files

I have above 50000 files ( audio, images, pdf) on AWS S3 bucket.Now i am facing a problem with firefox. Audio file is not playing on firefox because of their content-type. Before it was working well.

Audio file works good when i change the content-type from binary/octet-stream to audio/mpeg.

The default content-type ( binary/octet-stream ) is assigned for all existing files.

I also tried s3 bucket explorer tool but there are no option to change the content-type specifically for audio files.

how can i change content type only for audio files?

Is there any example by aws php sdk?

Thanks in advance

like image 426
Rajaraman Avatar asked Mar 18 '23 07:03

Rajaraman


1 Answers

I also ran into this problem, and as the author pointed out, this is the way to fix it using the s3cmd tool:

s3cmd --recursive modify                             \ 
    --acl-public                                     \
    --add-header='Cache-Control: max-age=94608000'   \
    --add-header='content-type':'audio/mpeg'         \
    --exclude '' --include '.mp3'                    \
    s3://<your-bucket-name>/                         \

The --recursive modify flag tells s3cmd to recuse into your bucket and find all files to modify; --acl-public opens modified files for public access; --add-header='Cache-Control sets the amount of time in seconds the cache can keep the file (so people getting the file from your bucket won't need to download it a second time, if the file hasn't changed). --exclude '' --include 'mp3' instructs s3cmd to exclude all files from the process, except the ones matching the specified pattern. Here is another example, setting all css files in your bucket to text/css:

s3cmd --recursive modify --add-header='content-type':'text/css' \
      --exclude '' --include '.css' s3://<your-bucket-name>/

If you are not sure what kind of content-type to specify for your specific type of file, check out this list of most common mimetypes: http://hul.harvard.edu/ois/systems/wax/wax-public-help/mimetypes.htm

like image 109
Wladston Ferreira Filho Avatar answered Mar 21 '23 04:03

Wladston Ferreira Filho