以编程方式恢复使用BlobInfo在BlobStore中上传的Blob的ServingUrl?

时间:2014-08-22 12:39:01

标签: java google-app-engine blobstore

我想使用BlobInfo实体恢复BlobStore上传的Blob的ServingUrl

My doGet()方法中的代码是:

        ImagesService imagesService = ImagesServiceFactory.getImagesService();

        Iterator<BlobInfo> iterator = null;
        iterator = new BlobInfoFactory().queryBlobInfos();
        while (iterator.hasNext()) {
            if(iterator.next().getFilename().equals("test.png"))
            { resp.getWriter().println(iterator.next().getBlobKey()) ;//  the result is  <BlobKey: aKQyp27ZfDgvEdPE8QvMAQ>
             resp.getWriter().println(iterator.next().getFilename());//the result is test.png
            BlobKey bk=iterator.next().getBlobKey();
            String urlStr=imagesService.getServingUrl(ServingUrlOptions.Builder.withBlobKey(bk));
            resp.getWriter().println(urlStr);
            }
        }

我收到了这个错误:

HTTP ERROR 500

访问/ enrollementFinale时遇到问题。原因是:

INTERNAL_SERVER_ERROR

引起:

java.util.NoSuchElementException     在com.google.appengine.api.datastore.QueryResultIteratorImpl.next(QueryResultIteratorImpl.java:75)     在com.google.appengine.api.datastore.QueryResultIteratorImpl.next(QueryResultIteratorImpl.java:26)     在com.google.appengine.api.blobstore.BlobInfoFactory $ 1.next(BlobInfoFactory.java:108)     在com.google.appengine.api.blobstore.BlobInfoFactory $ 1.next(BlobInfoFactory.java:100)     at com.EnrollementFinaleServlet.doGet(EnrollementFinaleServlet.java:135)     在javax.servlet.http.HttpServlet.service(HttpServlet.java:617)     在javax.servlet.http.HttpServlet.service(HttpServlet.java:717)     在org.mortbay.jetty.servlet.ServletHolder.handle(ServletHolder.java:511)     在org.mortbay.jetty.servlet.ServletHandler $ CachedChain.doFilter(ServletHandler.java:1166)     在com.google.appengine.api.socket.dev.DevSocketFilter.doFilter(DevSocketFilter.java:74)     在org.mortbay.jetty.servlet.ServletHandler $ CachedChain.doFilter(ServletHandler.java:1157)     在com.google.appengine.tools.development.ResponseRewriterFilter.doFilter(ResponseRewriterFilter.java:127)     在org.mortbay.jetty.servlet.ServletHandler $ CachedChain.doFilter(ServletHandler.java:1157)     在com.google.appengine.tools.development.HeaderVerificationFilter.doFilter(HeaderVerificationFilter.java:34)     在org.mortbay.jetty.servlet.ServletHandler $ CachedChain.doFilter(ServletHandler.java:1157)     在com.google.appengine.api.blobstore.dev.ServeBlobFilter.doFilter(ServeBlobFilter.java:63)     在org.mortbay.jetty.servlet.ServletHandler $ CachedChain.doFilter(ServletHandler.java:1157)     在com.google.apphosting.utils.servlet.TransactionCleanupFilter.doFilter(TransactionCleanupFilter.java:43)     在org.mortbay.jetty.servlet.ServletHandler $ CachedChain.doFilter(ServletHandler.java:1157)     在com.google.appengine.tools.development.StaticFileFilter.doFilter(StaticFileFilter.java:125)     在org.mortbay.jetty.servlet.ServletHandler $ CachedChain.doFilter(ServletHandler.java:1157)     在com.google.appengine.tools.development.DevAppServerModulesFilter.doDirectRequest(DevAppServerModulesFilter.java:366)     在com.google.appengine.tools.development.DevAppServerModulesFilter.doDirectModuleRequest(DevAppServerModulesFilter.java:349)     在com.google.appengine.tools.development.DevAppServerModulesFilter.doFilter(DevAppServerModulesFilter.java:116)     在org.mortbay.jetty.servlet.ServletHandler $ CachedChain.doFilter(ServletHandler.java:1157)     在org.mortbay.jetty.servlet.ServletHandler.handle(ServletHandler.java:388)     在org.mortbay.jetty.security.SecurityHandler.handle(SecurityHandler.java:216)     在org.mortbay.jetty.servlet.SessionHandler.handle(SessionHandler.java:182)     在org.mortbay.jetty.handler.ContextHandler .__句柄(ContextHandler.java:765)     at org.mortbay.jetty.handler.ContextHandler.handle(ContextHandler.java)     在org.mortbay.jetty.webapp.WebAppContext.handle(WebAppContext.java:418)     在com.google.appengine.tools.development.DevAppEngineWebAppContext.handle(DevAppEngineWebAppContext.java:98)     在org.mortbay.jetty.handler.HandlerWrapper.handle(HandlerWrapper.java:152)     在com.google.appengine.tools.development.JettyContainerService $ ApiProxyHandler.handle(JettyContainerService.java:490)     在org.mortbay.jetty.handler.HandlerWrapper.handle(HandlerWrapper.java:152)     在org.mortbay.jetty.Server.handle(Server.java:326)     在org.mortbay.jetty.HttpConnection.handleRequest(HttpConnection.java:542)     at org.mortbay.jetty.HttpConnection $ RequestHandler.headerComplete(HttpConnection.java:923)     在org.mortbay.jetty.HttpParser.parseNext(HttpParser.java:547)     在org.mortbay.jetty.HttpParser.parseAvailable(HttpParser.java:212)     在org.mortbay.jetty.HttpConnection.handle(HttpConnection.java:404)     在org.mortbay.io.nio.SelectChannelEndPoint.run(SelectChannelEndPoint.java:409)     在org.mortbay.thread.QueuedThreadPool $ PoolThread.run(QueuedThreadPool.java:582)

由Jetty提供://

如果你帮助我,我将非常感激。

1 个答案:

答案 0 :(得分:0)

问题解决了,它是由两行引起的:

resp.getWriter().println(iterator.next().getBlobKey());
resp.getWriter().println(iterator.next().getFilename());