简体   繁体   中英

Audio URL get downloaded instead of playing in the browser - DigitalOcean Spaces/Buckets

I am using DigitalOcean Spaces/Buckets to store audio files and have a URL being generated which points to that file. In my html file, I am accessing that audio as:

<audio controls>
   <source src="my_digital_ocean_file_url">
</audio>

This file is not getting played on the front-end and when I enter the URL on chrome, the file gets downloaded instead of playing on the browser. Is there a way to make the files on the URL playable?

This is related to the backend. You need to provide 'contentType' as audio. The implementation is different based on the programming language you are using for the backend. Please check the sample code in PHP.

 $s3->create_object($bucket, $file_name, array(
                    'fileUpload' => $resized_image,
                    'contentType' => $_FILES['image']['type'],
                    'acl' => AmazonS3::ACL_PUBLIC
            ));

The above issue is not limited to audio files, it's for PDF, Images as well. Follow are some helpful reference

How to view pdf's stored in spaces without them being downloaded

amazon s3 - image downloading instead of displaying in the browser

I was using and outdated browser. Updating the browser solved the issues for me.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM