【发布时间】:2014-03-02 07:58:02
【问题描述】:
所以我正在尝试将使用 Flask 编写的 Python webapp 移植到 Google App Engine。该应用程序托管用户上传的最大 200mb 的文件,对于非图像文件,需要保留文件的原始名称。为了防止文件名冲突,例如两个人上传 stuff.zip,每个人都包含完全不同且不相关的内容,该应用程序在文件系统上创建一个 UUID 文件夹并将文件存储在其中,并将其提供给用户。 Google App Engine 的 Cloud Storage,我计划通过制作一个存储桶来存储用户文件——根据他们的文档,它“没有文件夹的概念”。使用他们的系统获得相同功能的最佳方法是什么?
目前的方法,仅供演示:
# generates a new folder with a shortened UUID name to save files
# other than images to avoid filename conflicts
else:
# if there is a better way of doing this i'm not clever enough
# to figure it out
new_folder_name = shortuuid.uuid()[:9]
os.mkdir(
os.path.join(app.config['FILE_FOLDER'], new_folder_name))
file.save(
os.path.join(os.path.join(app.config['FILE_FOLDER'], new_folder_name), filename))
new_folder_path = os.path.join(
app.config['FILE_FOLDER'], new_folder_name)
return url_for('uploaded_file', new_folder_name=new_folder_name)
【问题讨论】:
标签: python google-app-engine flask