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:
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.
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
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.
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.