Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to set filename property in BlobStore?

I'm programatically uploading image files and want to set the filename. When I upload a file via POST, the filename property is set automatically. However when using the method below, the filename is not getting set.

        image = urllib2.urlopen(url)
        file_name = files.blobstore.create(mime_type='image/png')
        with files.open(file_name, 'a') as f:
            f.write(image.read())
        files.finalize(file_name)  
        image_blob_key = files.blobstore.get_blob_key(file_name) 
like image 566
Will Curran Avatar asked Feb 02 '23 19:02

Will Curran


1 Answers

Parse the filename from the url (see related question here). Then you can set it by adding an additional parameter to your files.blobstore.create call:

file_name = files.blobstore.create(mime_type='image/png',_blobinfo_uploaded_filename=file_name_from_url)
like image 174
Kevin P Avatar answered Feb 05 '23 08:02

Kevin P