获取名称和使用python扩展上传的文件(谷歌应用程序引擎) [英] Getting the name & extension of an uploaded file using python (google app engine)
问题描述
我正在使用表单将文件上传到Google应用引擎并将其存储在数据存储中。 l还希望存储原始文件名和扩展名以用于演示目的。
是否有从检索服务器端检索此数据的方法,或只能收集客户端并作为单独的字段发送(例如 http://www.tinyurl.com/5jybfq )?
非常感谢。
对于那些遵循以下答案的解决方案: >
this_file = self.request.params [file_upload_form_field_name]。filename
(this_file_name (this_file_extension)= os.path.splitext(this_file)
self.response.out.write(文件名:+ this_file_name +< br>)
self.response.out.write(File extension:+ this_file_extension +< br>)
请阅读 I am using a form to upload files to the google app engine and store them in the datastore. l would also like to store the original file name and extension for presentation purposes. Is there a way of retrieving this data from the post sever side or can it only be gathered client side and sent as separate fields (e.g. http://www.tinyurl.com/5jybfq)? Many thanks. For those that follow the solution dased on the answer below:
Does the snippet from this email work?
这篇关于获取名称和使用python扩展上传的文件(谷歌应用程序引擎)的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
self.request.params [<包含文件的表单元素名称> ] .filename
this_file = self.request.params["file_upload_form_field_name"].filename
(this_file_name, this_file_extension) = os.path.splitext(this_file)
self.response.out.write("File name: " + this_file_name + "<br>")
self.response.out.write("File extension: " + this_file_extension + "<br>")
self.request.params[<form element name with file>].filename