我正在尝试使用 blobstore API,但出现此错误:
com.google.api.server.spi.SystemService invokeServiceMethod:调用支持的方法 com.google.apphosting.api.ApiProxy$CallNotFoundException 时发生异常:未找到 API 包“文件”或调用“Create()”。在 java.lang.Thread.getStackTrace(Thread.java:1589) 在 com.google.apphosting.api.ApiProxy.makeSyncCall(ApiProxy.java:116) 在 com.google.apphosting.api.ApiProxy.makeSyncCall(ApiProxy.java :65) com.google.appengine.api.files.FileServiceImpl.makeSyncCall(FileServiceImpl.java:590) com.google.appengine.api.files.FileServiceImpl.create(FileServiceImpl.java:512) com.google。 appengine.api.files.FileServiceImpl.createNewBlobFile(FileServiceImpl.java:111) 在 com.listecourses.model.ListeModelEndpoint.insertListeModel(ListeModelEndpoint.java:182) 在 sun.reflect。
我使用这段代码:
@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;
}
你能帮助我吗?