鉴于视频的BlobKey如何获取网址

时间:2015-10-13 21:44:58

标签: google-app-engine video mp4 blobstore

通常,要从BlobKey获取网址,我只需执行

public static String getUrlFromKey(BlobKey blobKey) {
    if(null == blobKey)return null;
    ServingUrlOptions options = ServingUrlOptions.Builder.withBlobKey(blobKey).secureUrl(false);
    String servingUrl = ImagesServiceFactory.getImagesService().getServingUrl(options);
    return servingUrl;
  }

但我现在得到一个例外,我说服原因是因为这次Blobkey是用于视频而不是图像。那么如何根据视频的Blobkey获取网址?

对于某些背景,我正在为我的Android应用程序使用Cloud Endpoint App-Engine服务器。将视频上传到Blobstore后,我需要能够从我的Android设备上观看。因此,如果无法按照图像的方式获取网址,是否有办法从端点方法提供服务?

错误:

com.google.appengine.api.images.ImagesServiceFailureException: 
    at com.google.appengine.api.images.ImagesServiceImpl.getServingUrl(ImagesServiceImpl.java:284)
    at com.mycompany.utils.BlobstoreUtils.getUrlFromKey(BlobstoreUtils.java:21)
    at com.mycompany.servlet.VideoUploadCallback.doPost(VideoUploadCallback.java:44)
    at javax.servlet.http.HttpServlet.service(HttpServlet.java:637)
    at javax.servlet.http.HttpServlet.service(HttpServlet.java:717)
    at org.mortbay.jetty.servlet.ServletHolder.handle(ServletHolder.java:511)
    at org.mortbay.jetty.servlet.ServletHandler$CachedChain.doFilter(ServletHandler.java:1166)
    at com.googlecode.objectify.ObjectifyFilter.doFilter(ObjectifyFilter.java:48)
    at org.mortbay.jetty.servlet.ServletHandler$CachedChain.doFilter(ServletHandler.java:1157)
    at com.google.apphosting.utils.servlet.ParseBlobUploadFilter.doFilter(ParseBlobUploadFilter.java:123)
    at org.mortbay.jetty.servlet.ServletHandler$CachedChain.doFilter(ServletHandler.java:1157)
    at com.google.apphosting.runtime.jetty.SaveSessionFilter.doFilter(SaveSessionFilter.java:37)
    at org.mortbay.jetty.servlet.ServletHandler$CachedChain.doFilter(ServletHandler.java:1157)
    at com.google.apphosting.utils.servlet.JdbcMySqlConnectionCleanupFilter.doFilter(JdbcMySqlConnectionCleanupFilter.java:60)
    at org.mortbay.jetty.servlet.ServletHandler$CachedChain.doFilter(ServletHandler.java:1157)
    at com.google.apphosting.utils.servlet.TransactionCleanupFilter.doFilter(TransactionCleanupFilter.java:43)
    at org.mortbay.jetty.servlet.ServletHandler$CachedChain.doFilter(ServletHandler.java:1157)
    at org.mortbay.jetty.servlet.ServletHandler.handle(ServletHandler.java:388)
    at org.mortbay.jetty.security.SecurityHandler.handle(SecurityHandler.java:216)
    at org.mortbay.jetty.servlet.SessionHandler.handle(SessionHandler.java:182)
    at org.mortbay.jetty.handler.ContextHandler.handle(ContextHandler.java:765)
    at org.mortbay.jetty.webapp.WebAppContext.handle(WebAppContext.java:418)
    at com.google.apphosting.runtime.jetty.AppVersionHandlerMap.handle(AppVersionHandlerMap.java:260)
    at org.mortbay.jetty.handler.HandlerWrapper.handle(HandlerWrapper.java:152)
    at org.mortbay.jetty.Server.handle(Server.java:326)
    at org.mortbay.jetty.HttpConnection.handleRequest(HttpConnection.java:542)
    at org.mortbay.jetty.HttpConnection$RequestHandler.headerComplete(HttpConnection.java:923)
    at com.google.apphosting.runtime.jetty.RpcRequestParser.parseAvailable(RpcRequestParser.java:78)
    at org.mortbay.jetty.HttpConnection.handle(HttpConnection.java:404)
    at com.google.apphosting.runtime.jetty.JettyServletEngineAdapter.serviceRequest(JettyServletEngineAdapter.java:147)
    at com.google.apphosting.runtime.JavaRuntime$RequestRunnable.run(JavaRuntime.java:457)
    at com.google.tracing.TraceContext$TraceContextRunnable.runInContext(TraceContext.java:437)
    at com.google.tracing.TraceContext$TraceContextRunnable$1.run(TraceContext.java:444)
    at com.google.tracing.CurrentContext.runInContext(CurrentContext.java:230)
    at com.google.tracing.TraceContext$AbstractTraceContextCallback.runInInheritedContextNoUnref(TraceContext.java:308)
    at com.google.tracing.TraceContext$AbstractTraceContextCallback.runInInheritedContext(TraceContext.java:300)
    at com.google.tracing.TraceContext$TraceContextRunnable.run(TraceContext.java:441)
    at com.google.apphosting.runtime.ThreadGroupPool$PoolEntry.run(ThreadGroupPool.java:235)
    at java.lang.Thread.run(Thread.java:745)

1 个答案:

答案 0 :(得分:0)

来自文档:

  

要提供blob,必须包含blob下载处理程序作为路径   你的申请。这个处理程序应该传递blob键   所需blob到blobstoreService.serve(blobKey,res);.在这   例如,blob密钥作为URL传递给下载处理程序   参数(req.getParameter('blob-key'))。在实践中,下载   handler可以通过您选择的任何方式获取blob密钥,例如through   另一种方法或用户操作。

public void doGet(HttpServletRequest req, HttpServletResponse res)
    throws IOException {
        BlobKey blobKey = new BlobKey(req.getParameter("blob-key"));
        blobstoreService.serve(blobKey, res);

使用Google Cloud Storage而不是Blobstore。然后,您可以直接投放视频 - 只需传递视频的网址,而无需通过您的应用程序。