How to set filename property in BlobStore?

落花浮王杯 提交于 2019-12-21 09:21:36

问题


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) 

回答1:


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)



回答2:


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.



来源:https://stackoverflow.com/questions/5697844/how-to-set-filename-property-in-blobstore

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!