开发者

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) 


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)


I know this is an old question but ...

self.send_blob(blob_info,save_as=True) allows you instead of True, to specify a string. What that means is that the file will be served with the provided string as the filename. So one solution is for you to keep the filename along with the blobkey, and then when you serve these using send_blob, you provide the filename as an argument. You don't care how the file will be stored, you only care how it will be served.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜