5

I'm uploading multiple pictures with different extensions (jpg, png...etc) via java Amazon TransferManager.

for example : picture1.png, picture2.jpg. I would like to serve the content without the extension, a get request to folder/picture1 would return picture1.png.

The client is an angularJs application

Previously, I was hosting all these picture on EC2 and serving it via APACHE with option Multiviews, is there something similar we can do with AmazonS3?

starball
  • 20,030
  • 7
  • 43
  • 238
daley
  • 177
  • 1
  • 2
  • 9

2 Answers2

20

It doesn't work that way. S3 does not impute special meaning to any portion of the object key (path + filename), so it has no concept of "extensions." (Technically, S3 has no real concept of "paths" either, but it behaves in most cases as though it does).

Of course, on the web, file extensions should have no meaning anyway -- the Content-Type declared should be the only thing that matters, so... technically... there's no need for objects in S3 to be saved with their extension.

Save the files to S3 without the extension, set the Content-Type correctly, and you'll have exactly the behavior you're looking for.

Michael - sqlbot
  • 169,571
  • 25
  • 353
  • 427
  • Michael, thanks for the clear and accurate answer. I did search some more and ended up finding the same solution. – daley Jul 31 '16 at 09:27
-2

What you can do is list all the files from the aws s3 folder like this

const files = await s3Bucket.listObjects(params).promise()

The you can go through each file and match it with you document and what you want to do.

 files.Contents.forEach(function(obj,index){
                    obj.Key //
                })

You can now use this obj.Key to access your file. obj.Key is the full path of your file wih extension. You can search this string or match this with your file and then get the file.

Nouman Dilshad
  • 1,014
  • 13
  • 16