我想上傳表單中的多個文件到BlobStore。如何將多個文件上傳到BlobStore?
形式:
<form action="{{upload_url}}" method="POST" enctype="multipart/form-data">
<label>Key Name</label><input type="text" name="key_name" size="50"><br/>
<label>name</label><input type="text" name="name" size="50"><br/>
<label>image</label><input type="file" name="image" size="50"><br/>
<label>thumb</label><input type="file" name="thumb" size="50"><br/>
<input type="submit" name="submit" value="Submit">
</form>
然後我試圖獲取的BlobInfo對象爲每個上傳這些文件:
def post(self):
image_upload_files = self.get_uploads('image')
thumb_upload_files = self.get_uploads('thumb')
image_blob_info = image_upload_files[0]
thumb_blob_info = thumb_upload_files[0]
我看到一些奇怪的行爲。這兩個文件都進入BlobStore,但我不知道如何獲得密鑰,以便我可以將其存儲在另一個實體上。上面的代碼設法獲取image_blob_info的密鑰,但不是thumb_blob_info。我不明白如何使用get_uploads。我想通過表單傳遞多個文件,然後按名稱獲取它們,以便將它們存儲在另一個實體的相應BlobReferenceProperties中。
我最終什麼事做的是創建兩個UPLOAD_URL變量,因爲我只需要兩個上傳兩個文件一次。如果您有n個要上傳的文件,則Karl引用的解決方案非常好(但實現起來並不容易)。 – 2011-01-22 15:37:57
您是否有理由要求用戶上傳縮略圖?你知道get_serving_url,它可以讓你從全尺寸圖像生成縮略圖嗎? – 2011-01-24 01:56:31