【问题标题】:serving blob giving 404 error服务 blob 给出 404 错误
【发布时间】:2012-11-10 21:58:46
【问题描述】:

我正在尝试从存储在 db.Model 中的 blobKey 作为 blobstore.BlobReferenceProperty() 提供 blob,但我不确定如何正确执行此操作,因为我当前的方法给出了 404。我通过使用常规 self.request.get('file_field') 接受“重写”请求来存储 blobKey 值

密钥的内容在 SDK 控制台中如下所示:

Content-Type: video/mp4
MIME-Version: 1.0
Content-Length: 475712
Content-MD5: OTY0MjY4OGI4NDgwYzVlZTI2MGJiNzg0YTA4OTIzNzY=
content-type: video/mp4
content-disposition: form-data; name="video_file"; filename="test_time.mp4"
X-AppEngine-Upload-Creation: 2012-11-10 21:41:12.973934

我的视频下载处理程序非常标准,看起来像这样

class VideoServeHandler(blobstore_handlers.BlobstoreDownloadHandler):
  def get(self, resource):
    resource = str(urllib.unquote(resource))
    blob_info = blobstore.BlobInfo.get(resource)
    self.send_blob(blob_info)

这是我呈现网址的方式:

'/videos/%s' % time_data_instance.video_key.key()

还有url映射:

('/videos/([^/]+)?', VideoServeHandler)

这是我从控制台得到的 404 错误:

INFO     2012-11-10 21:54:11,371 dev_appserver.py:3092] "GET /videos/Content-Type:%20video/mp4MIME-Version:%201.0Content-Length:%20475712Content-MD5:%20OTY0MjY4OGI4NDgwYzVlZTI2MGJiNzg0YTA4OTIzNzY=content-type:%20video/mp4content-disposition:%20form-data;%20name= HTTP/1.1" 404 -

有人知道问题可能是什么吗,看看 404 中的 url,它看起来好像不正确,但我找不到任何其他方法来生成它

更新:

这是整个代码

http://www.pastebucket.com/5163

【问题讨论】:

    标签: python google-app-engine blobstore


    【解决方案1】:

    send_blob 需要 BlobKey,而不是 BlobInfo。

    只需将资源传递给 send_blob

    class VideoServeHandler(blobstore_handlers.BlobstoreDownloadHandler):
      def get(self, resource):
        resource = str(urllib.unquote(resource))
        self.send_blob(resource)
    

    【讨论】:

    • 我似乎仍然收到 404,它尝试获取的网址对您来说是否正确?
    • 我刚刚在主要问题中添加了指向整个代码的链接,pastebucket.com/5163
    【解决方案2】:

    问题在于您的请求字符串:

    INFO     2012-11-10 21:54:11,371 dev_appserver.py:3092] "GET /videos/Content-Type:%20video/mp4MIME-Version:%201.0Content-Length:%20475712Content-MD5:%20OTY0MjY4OGI4NDgwYzVlZTI2MGJiNzg0YTA4OTIzNzY=content-type:%20video/mp4content-disposition:%20form-data;%20name= HTTP/1.1" 404 -
    

    据我所知,您请求 /videos/Content-Type:%20video/mp4[..some garbage...],难怪您会收到 404 回复。

    再次检查您如何提出请求 URL。绝对不是这样的:

    '/videos/%s' % time_data_instance.video_key.key()
    

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 2013-08-28
      • 1970-01-01
      • 2012-04-24
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2014-05-06
      相关资源
      最近更新 更多