How does one determine the filetype on an AWS S3 hosted file without the extension?

TRose

As an example, I'm currently uploading items directly to an S3 bucket using a form. While I was testing, I didn't specify any expected filenames or extensions.

I uploaded a .png which produced this direct link:

https://s3-us-west-2.amazonaws.com/easyhighlighting2/2015-07-271438019663927upload94788

When I place this inside an img tag, it displays on a web page properly.

My question is, without an extension, how would my browser know what type of file it's loading? Inside the bucket, the file's metadata isn't even filled out.

Is there any way to get that file extension, programmatically?

I'm ready to try any clientside methods available; my server-side language is ColdFusion which is somewhat limiting, but I'm open to suggestions for that as well.

TRose

Okay, so after some more extensive digging, I found a method of retrieving the file's type that was only added since CF10 was released; that would explain the lack of documentation.

The answer lies in the FileGetMimeType function.

<cfset someVar = "https://s3-us-west-2.amazonaws.com/easyhighlighting2/2015-07-271438019663927upload94788">
<cfset FileType = FileGetMimeType(someVar)>
<cfoutput>#FileType#</cfoutput>

This code would output image/png - which is correct and has worked for every filetype I have tested thus far.

I'm surprised this kind of question hasn't popped up before, but this appears to be the best answer, at least for users of CFML.

Edit:

ColdFusion accomplishes this by either reading the contents of a file, or by trusting its extension. An implicit attribute, 'strict', is used in this function. If true, it reads the file's contents. If false, it uses the provided extension.

True is the default.

Link:

https://wikidocs.adobe.com/wiki/display/coldfusionen/FileGetMimeType

Collected from the Internet

Please contact [email protected] to delete if infringement.

edited at
0

Comments

0 comments
Login to comment

Related

From Dev

In vim, how does one apply autocommands for a filetype to a region of a file?

From Dev

How to upload file to S3 without AWS JavaScript SDK?

From Dev

How can I determine file type without an extension on Windows?

From Dev

Amazon S3 get file without extension

From Dev

How does Ubuntu know what file type a file without extension is?

From Dev

How does Ubuntu know what file type a file without extension is?

From Dev

How to lookup to S3 file in AWS Lambda function without download it first?

From Dev

How to lookup to S3 file in AWS Lambda function without download it first?

From Dev

How does a program determine the size of a file without reading it whole?

From Dev

How can I determine a file's conventional filename extension

From Dev

How can I tell the filetype of images without extension? How do they work?

From Dev

Vim: gf with file extension based on current FileType

From Dev

Boto does not save s3 file to disc on AWS Lambda

From Dev

In Ruby how can I tell what the extension is to an image file that's hosted on the internet?

From Dev

How to determine the mime type of a file being hosted by a remote server?

From Dev

How to determine mime type by the file extension? ( Ruby )

From Dev

How to determine if SearchPattern effects extension of file?

From Dev

How to determine mime type by the file extension? ( Ruby )

From Dev

How to set the Content Disposition header with Paperclip / fog for a file hosted on S3?

From Dev

How to determine if a file is identical to one in git's history

From Dev

How to determine if a file is identical to one in git's history

From Dev

Why does page not load without file extension

From Dev

How to parse an AWS S3 file from a Lambda function

From Dev

how to set a unique aws S3 file name?

From Dev

How to decrypt AWS S3 file during download?

From Dev

AWS S3 change the file extension when using putObject(String,String,String)

From Java

How to edit a S3 CSV file without downloading?

From Dev

filetype filter does not work in php file upload

From Dev

Using custom fonts hosted on AWS S3 in a Wordpress site

Related Related

  1. 1

    In vim, how does one apply autocommands for a filetype to a region of a file?

  2. 2

    How to upload file to S3 without AWS JavaScript SDK?

  3. 3

    How can I determine file type without an extension on Windows?

  4. 4

    Amazon S3 get file without extension

  5. 5

    How does Ubuntu know what file type a file without extension is?

  6. 6

    How does Ubuntu know what file type a file without extension is?

  7. 7

    How to lookup to S3 file in AWS Lambda function without download it first?

  8. 8

    How to lookup to S3 file in AWS Lambda function without download it first?

  9. 9

    How does a program determine the size of a file without reading it whole?

  10. 10

    How can I determine a file's conventional filename extension

  11. 11

    How can I tell the filetype of images without extension? How do they work?

  12. 12

    Vim: gf with file extension based on current FileType

  13. 13

    Boto does not save s3 file to disc on AWS Lambda

  14. 14

    In Ruby how can I tell what the extension is to an image file that's hosted on the internet?

  15. 15

    How to determine the mime type of a file being hosted by a remote server?

  16. 16

    How to determine mime type by the file extension? ( Ruby )

  17. 17

    How to determine if SearchPattern effects extension of file?

  18. 18

    How to determine mime type by the file extension? ( Ruby )

  19. 19

    How to set the Content Disposition header with Paperclip / fog for a file hosted on S3?

  20. 20

    How to determine if a file is identical to one in git's history

  21. 21

    How to determine if a file is identical to one in git's history

  22. 22

    Why does page not load without file extension

  23. 23

    How to parse an AWS S3 file from a Lambda function

  24. 24

    how to set a unique aws S3 file name?

  25. 25

    How to decrypt AWS S3 file during download?

  26. 26

    AWS S3 change the file extension when using putObject(String,String,String)

  27. 27

    How to edit a S3 CSV file without downloading?

  28. 28

    filetype filter does not work in php file upload

  29. 29

    Using custom fonts hosted on AWS S3 in a Wordpress site

HotTag

Archive