Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with
or
.
Download ZIP

Loading…

boto.s3.key.Key.set_contents_from_filename() incorrectly urlencodes 'attachment; filename=""' header value #1381

Open
dpapathanasiou opened this Issue · 1 comment

1 participant

@dpapathanasiou

I have Content-Disposition header values that look like this:

attachment; filename*=UTF-8''My Human-Readable Filename.pdf

But when I view the metadata information on the S3 console, after uploading, it has
been urlencoded like this:

attachment%3B+filename%2A%3DUTF-8%27%27My+Human-Readable
+Filename.pdf

So when I download the file, it ignores the Content-Disposition header entirely, which defeats the purpose of having it.

Any way of getting boto to pass the Content-Disposition value correctly?

Here's what I'm doing currently:

    # create a key to keep track of our file in the storage 
    k = Key(bucket)
    k.key = file_base_name(filename)
    # set the content-disposition so that when downloaded it has the human readable title instead of the pdf uuid
    content_disposition = u''.join(["attachment; filename*=UTF-8''", human_readable_filename, '.pdf'])
    k.set_contents_from_filename(filename, headers={'Content-Disposition':content_disposition}) # but adds unwanted urlencoding :(


    # make it public so it can be accessed
    # using a URL like http://s3.amazonaws.com/bucket_name/key
    k.make_public()
@dpapathanasiou

There's a partial answer to this problem (thanks to Tony for suggesting it): https://groups.google.com/d/msg/boto-users/17M3eRUX0_0/4R4TmOjOfokJ

But it remains unresolved for file names which require unicode.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Something went wrong with that request. Please try again.