New user: S3 request returning file of different name?

dreamobjects

#1

Hi guys,
I’m interested in doing the following with S3 storage:
If i request: http://mybucket.domain.com/12345
I get a mp3 file named: “spades.mp3”

Is it possible to return a file name that is different to the pointer in the url?
Assuming 12345 is a unique reference, how would I go implementing this?

(Should I store the files in S3 by the end file name, eg “spades.mp3” or should I store the file with the name “12345”? How do I get S3 to deliver it as a different name?)

(I also don’t fully understand MIME types with S3 storage yet.)

Thanks,
Graham


#2

You may be able to achieve that by using the Content-Disposition header in DreamObjects response. I see here https://discussion.dreamhost.com/thread-136154.html that the option is available.

You may start learning about it here: http://docs.aws.amazon.com/AmazonS3/latest/API/RESTObjectGET.html

If you write a tutorial on how to do this, you can get free credit from DreamHost. Check https://github.com/dreamhost/dreamcloud-docs/blob/master/CONTRIBUTING.rst


#3

Stefano is correct, you’re looking for the Content-Disposition header. In your example, if you have an object called “12345” you could set the Content-Disposition header to be attachment; filename="spades.mp3" and when someone clicks the link for 12345, that file will be downloaded with the name spades.mp3.

An easy way to set the header is with a client like Cyberduck. You can modify an object’s metadata and add the content-disposition header with your own custom value - https://trac.cyberduck.io/wiki/help/en/howto/info#MetadataHTTPheaders