gpt4 book ai didi

结合 requestHandler 和 BlobstoreUploadHandler 的 Python GAE 问题

转载 作者:太空宇宙 更新时间:2023-11-04 03:51:23 25 4
gpt4 key购买 nike

<form action="/fileupload" enctype="multipart/form-data" method="post">
<label>Title<input name="name"></label>
<label>Author<input name="author"></label>
<label>Year <input name="year"></label>
<label>Link <input name="link"></label>
<input type="file" name="file">
<input type="submit">
</form>

问题是为什么 self.get_uploads()self.request.get('file') 工作时(或者我建议它工作)什么都不返回

class FileUploadHandler(H.Handler,blobstore_handlers.BlobstoreUploadHandler):
def post(self):
name=self.request.get('name')
if name:
logging.error(name)
author=self.request.get('author')
if author:
logging.error(author)
year =self.request.get('year')
if year and year.isdigit():
year=int(year)
f =self.get_uploads('file')#FILE NOT FOUND
#f=self.request.get('file') # WORKS FINE

if not f:
logging.error("FILE NOT FOUND")
self.redirect("/files")

我查看了 sample app但他们也使用 self.request.get('file')

答案是您应该为 blob 创建上传 url。

最佳答案

您需要 get_uploads()[0] 或名称。

上传处理程序的简单示例(比较并在您的代码中进行适当的更改):

  <form name="myform" action="{{ upload_url }}" method="post" enctype="multipart/form-data">
<h1>Select an Image</h1>
<input name="file" type="file"><br>
<input type="submit" value="Upload">
</form>

处理程序:

class UploadBlobsHandler(blobstore_handlers.BlobstoreUploadHandler):

def post(self):
try:
upload = self.get_uploads()[0]
logging.info(upload)
url = images.get_serving_url(upload)
# Do something with it.
except:
self.redirect('/uploadform/?error', abort=True)

self.redirect('/uploadform/?success&image_url=' + url)

关于如何使用 blobstorrhandlers 上传的示例:gae-image-upload-example

关于结合 requestHandler 和 BlobstoreUploadHandler 的 Python GAE 问题,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/21141235/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com