我用这个问题作为模板来解决同样的问题,但是我在发布时遇到了问题。我有这些组件:
- 带有图像 URL 文本框的HTML表单。这个帖子到...
- 一个处理程序,它获取已发布的 URL,对其进行编码,并用于
urlfetch
再次将其发布到... - 执行实际保存的单独文件上传处理程序。
如果我使用文件输入,组件 #3 本身就可以正常工作。但我不太明白如何urlfetch
仅从图像 URL 中获取所需的内容。我的进程要么超时,要么从最终处理程序获得 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
同样,这是我正在遵循的过程。谢谢你的帮助!