简体   繁体   中英

Detect Content-Type/MIME Type of an S3 Object

I am sending a pre-signed URL, generated by my server using S3 SDK, to the client app. I can not decide in a first place if the URL will be used to upload either a MP4 video or a JPG image (so no Content-Type set in the pre-signed URL).

I will need to download that file later on the client (NodeJS - React Native).

Is there a way to determine the file format of the S3 Object (without being based on the filename) to then be able to view it with the proper tag (in this case, either <img> or <video> )?

Thanks a lot

Edit: I have just been thinking that maybe the client can set the content-type by itself when uploading? I am not sure if I will get an access denied by S3 since the Content-Type won't be defined in the pre-signed URL. This way I can know data type when downloading. Would that work? (Will try tomorrow though)

I would advise setting the content-type on PUT. But, when using signed URLs you can override the content-type and content-disposition.

S3 RESTObjectGET API

Example:

https://my.examplesite.com/some/path/file.jpg?response-content-type=image/jpeg&response-content-disposition=attachment;%20filename="coolcat.jpg"

Important Note: "Content-type" should precede "Content-Disposition" such as in the above example. Also these query string values are not included in the signature generation, they are added to the URL after the signature is generated.

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