当前位置: 首页 > 知识库问答 >
问题:

找不到API包“file”或调用“create()”

鲁英卫
2023-03-14

我使用以下代码:

@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;
        }

你能帮我吗?

暂时还没有答案

 类似资料: