如何在BlobStore中设置文件名属性? [英] How to set filename property in BlobStore?

查看:86
本文介绍了如何在BlobStore中设置文件名属性?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我以编程方式上传图片文件并想设置文件名。当我通过POST上传文件时,文件名属性会自动设置。然而,当使用下面的方法时,文件名不会被设置。

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) 


推荐答案

从url解析文件名(请参阅相关问题此处 )。然后,您可以通过向files.blobstore.create调用添加一个附加参数来设置它:

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)

这篇关于如何在BlobStore中设置文件名属性?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆