【发布时间】:2011-07-19 05:06:24
【问题描述】:
我使用this question 作为模板来解决同样的问题,但我在发布时遇到了问题。我有这些组件:
- HTML form 带有用于图像 URL 的文本框。此帖发给...
- 一个处理程序,获取发布的 URL,对其进行编码,然后使用
urlfetch再次将其发布到... - 一个单独的文件上传处理程序进行实际保存。
如果我使用文件输入,组件 #3 本身就可以正常工作。但我不太明白如何仅从图像 URL 中获取 urlfetch 所需的内容。我的进程要么超时,要么从最终处理程序获得 500 响应。
# 1
class URLMainHandler(RequestHandler):
def get(self):
return render_response('blob/upload_url.html',
upload_url=url_for('blobstore/upload/url'))
# 2
class URLUploadHandler(RequestHandler):
def post(self):
import urllib
# Get the posted image URL.
data = urllib.urlencode({'file': self.request.form.get('file')})
# Post image to blobstore by calling POST on the file upload handler.
result = urlfetch.fetch(url=blobstore.create_upload_url(url_for('blobstore/upload')),
payload=data,
method=urlfetch.POST)
return self.redirect(url_for('blobstore/url'), result.status_code)
# 3
class UploadHandler(RequestHandler, BlobstoreUploadMixin):
def post(self):
# 'file' is the name of the file upload field in the form.
upload_files = self.get_uploads('file')
blob_info = upload_files[0]
response = redirect_to('blobstore/serve', resource=blob_info.key())
# Clear the response body.
response.data = ''
return response
再次,this is the process I'm following。感谢您的帮助!
【问题讨论】:
-
#2 处理程序只有 30 秒的时间来获取文件并将其上传到 blobstore 处理程序。
标签: python image google-app-engine blobstore tipfy