1
votes

I am trying to use the blobstore API, but I have this error:

com.google.api.server.spi.SystemService invokeServiceMethod: exception occurred while calling backed method com.google.apphosting.api.ApiProxy$CallNotFoundException: The API package 'file' or call 'Create()' was not found. at java.lang.Thread.getStackTrace(Thread.java:1589) at com.google.apphosting.api.ApiProxy.makeSyncCall(ApiProxy.java:116) at com.google.apphosting.api.ApiProxy.makeSyncCall(ApiProxy.java:65) at com.google.appengine.api.files.FileServiceImpl.makeSyncCall(FileServiceImpl.java:590) at com.google.appengine.api.files.FileServiceImpl.create(FileServiceImpl.java:512) at com.google.appengine.api.files.FileServiceImpl.createNewBlobFile(FileServiceImpl.java:111) at com.listecourses.model.ListeModelEndpoint.insertListeModel(ListeModelEndpoint.java:182) at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method) at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:57) at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43) at java.lang.reflect.Method.invoke(Method.java:45) at com.google.api.server.spi.SystemService.invokeServiceMethod(SystemService.java:359) at com.google.api.server.spi.SystemServiceServlet.execute(SystemServiceServlet.java:113) at com.google.api.server.spi.SystemServiceServlet.doPost(SystemServiceServlet.java:71) 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 org.mortbay.jetty.servlet.ServletHandler$CachedChain.doFilter(ServletHandler.java:1157) at org.mortbay.jetty.servlet.ServletHandler$CachedChain.doFilter(ServletHandler.java:1157) at org.mortbay.jetty.servlet.ServletHandler$CachedChain.doFilter(ServletHandler.java:1157) 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 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 org.mortbay.jetty.HttpConnection.handle(HttpConnection.java:404) 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 java.lang.Thread.run(Thread.java:745)

I using this code:

@ApiMethod(name = "insertListeModel", httpMethod = "POST")
public ListeModel insertListeModel(ListeModel listemodel) {
    EntityManager mgr = getEntityManager();
    try {
        if (containsListeModel(listemodel)) {
            throw new EntityExistsException("Object already exists");
        }




        FileService fileService = FileServiceFactory.getFileService();
        if(listemodel.getImage()!=null && !listemodel.getImage().equals(""))
        {
            byte[] data = listemodel.getImage();




            String mimeType = "image/png";

            // save data to Google App Engine Blobstore 

            listemodel.setImage(null);
            mgr.persist(listemodel);
            AppEngineFile file;
                file = fileService.createNewBlobFile(mimeType,"LM_"+listemodel.getId());
                FileWriteChannel writeChannel = fileService.openWriteChannel(file, true);
                writeChannel.write(java.nio.ByteBuffer.wrap(data));
                writeChannel.closeFinally();

                // your blobKey to your data in Google App Engine BlobStore
                BlobKey blobKey = fileService.getBlobKey(file);

                // THANKS TO BLOBKEY YOU CAN GET FOR EXAMPLE SERVING URL FOR IMAGES

                //  UploadOptions uploadOptions = UploadOptions.Builder
                //          .withGoogleStorageBucketName("photobucket11");

                // Get the image serving URL (in https:// format)
                String imageUrl = ImagesServiceFactory.getImagesService().getServingUrl(ServingUrlOptions.Builder.withBlobKey(blobKey).secureUrl(true));

                //       ImagesService imagesService = ImagesServiceFactory
                //               .getImagesService();
                //      ServingUrlOptions servingOptions = ServingUrlOptions.Builder
                //               .withBlobKey(blobKey);

                //       String imageUrl = imagesService.getServingUrl(servingOptions);

                if(listemodel.getIdBlobkey()!=null)
                {
                    BlobKey blobKeytmp= new BlobKey(listemodel.getIdBlobkey());
                    final AppEngineFile f = fileService.getBlobFile(blobKeytmp);

                    if(f.isReadable())
                    {

                        if(f.hasFinalizedName())
                        {
                            fileService.delete(f); // Problematic line
                        }
                    }

                }

                listemodel.setAvatar(imageUrl);
                listemodel.setIdBlobkey(blobKey.getKeyString());
        }

                mgr.persist(listemodel);
            } catch (IOException e) {
                // TODO Auto-generated catch block
                e.printStackTrace();


            } finally {
                mgr.close();
            }
            return listemodel;
        }

Can you help me?

1
Got the solution for this? If so please share. Even 'm facing the same issue.das

1 Answers

0
votes

It appears that the files API was deprecated the in 2013, and finally disabled this year. See: https://cloud.google.com/appengine/docs/deprecations/files_api