我使用以下html表单在gae上传两个文件
<form id="insert-budget-form" method="POST" action="" enctype="multipart/form-data" onsubmit="return validate()">
Budget Book Name:<br> <input type = "text" id = "bookName" name = "bookName" placeholder = "E.g. Budget Book 2016"/>
<br><br>
File:<br> <input type = "file" id = "bookFile" name = "bookFile"/>
<br><br>
Highlight:<br> <input type="file" id = "highlightFile" name = "highlightFile"/>
<br><br>
<input type="date" id="bookDate" name="bookDate"/>
<input type="submit" id="insert-budget-sub" value="Insert"/>
</form>
当用户选择第一个文件并使用jQuery时,我正在使用ajax生成上传URL我将url指定为表单的动作
现在,在我的服务器端,我收到第一个文件,如何获取第二个文件。这是服务器端代码:
class BudgetBookUploadHandler(blobstore_handlers.BlobstoreUploadHandler):
def post(self):
bookName = self.request.POST.get('bookName')
bookDatetime = self.request.POST.get('bookDate')
dateParts = bookDatetime.split("-")
date = datetime.date(int(dateParts[0]), int(dateParts[1]), int(dateParts[2]))
if bookName != "" and date:
q = BudgetBook.query(BudgetBook.bookName == bookName)
if q.get():
self.redirect("/manage_budgetbook?success=dup")
else:
bookUpload = self.get_uploads()[0]
highlightUpload = self.get_uploads()[1]
budgetBook = BudgetBook(
bookBlobKey = bookUpload.key(),
highlightBlobKey = None,
bookName = bookName,
bookDate = date)
budgetBook.put()
self.redirect("/manage_budgetbook?success=true")
语法上getuploads()[1]是否正确用于获取第二个文件并存储它?
答案 0 :(得分:1)
而不是getuploads()[0]
和getuploads()[1]
使用getuploads('name of the form field')[0]