在图像上传期间,我使用以下方法getBlobKey来获取图像的 BlobKey 并将其详细信息保存在数据库中。
private BlobKey getBlobKey(byte[] data, String fileName) {
System.out.println("Inside getBlobKey....");
GcsService gcsService = null;
GcsFilename gcsFilename = null;
String bucket = "nirantGallery";
fileName = fileName + "_" + UUID.randomUUID().toString();
try {
gcsService = GcsServiceFactory.createGcsService();
gcsFilename = new GcsFilename(bucket, fileName);
GcsFileOptions.Builder options_builder = new GcsFileOptions.Builder();
options_builder = options_builder.mimeType("image/jpeg");
GcsFileOptions options = options_builder.build();
GcsOutputChannel output = GcsServiceFactory.createGcsService().createOrReplace(gcsFilename, options);
output.write(ByteBuffer.wrap(data));
output.close();
// Get serving url
String gs_blob_key = "/gs/" + bucket + "/" + fileName;
BlobKey blob_key = BlobstoreServiceFactory.getBlobstoreService().createGsBlobKey(gs_blob_key);
ServingUrlOptions serving_options = ServingUrlOptions.Builder.withBlobKey(blob_key);
String serving_url = ImagesServiceFactory.getImagesService().getServingUrl(serving_options);
System.out.println("Serving URL: " + serving_url);
return blob_key;
} catch (Exception e) {
System.out.println("Inside exception....");
e.printStackTrace();
} finally {
gcsService = null;
}
return null;
}
问题是当我在本地系统中运行它时,它可以工作并给我 localhost URL,比如
Serving URL: http://127.0.0.1:8888/_ah/img/encoded_gs_key:L2dzL25pcmFudEdhbGxlcnkvaW1hZ2VfMF9kNjlmOGFjMS05ZTUzLTRiNzUtOTI1ZC1hYzU0ZWQzNzJkNDk
但是当我部署和运行时它不起作用,检查登录服务器发现下面的详细信息。
Error for /nirat-admin-portal/addGallery
java.lang.NoClassDefFoundError: com/google/api/client/extensions/appengine/http/UrlFetchTransport
at com.google.appengine.tools.cloudstorage.oauth.OauthRawGcsServiceFactory.<clinit>(OauthRawGcsServiceFactory.java:31)
at com.google.appengine.tools.cloudstorage.GcsServiceFactory.createRawGcsService(GcsServiceFactory.java:59)
at com.google.appengine.tools.cloudstorage.GcsServiceFactory.createGcsService(GcsServiceFactory.java:44)
at com.google.appengine.tools.cloudstorage.GcsServiceFactory.createGcsService(GcsServiceFactory.java:40)
at com.google.appengine.tools.cloudstorage.GcsServiceFactory.createGcsService(GcsServiceFactory.java:75)
at com.sparks.nirant.datastore.DataStoreService.getBlobKey(DataStoreService.java:207)
at com.sparks.nirant.datastore.DataStoreService.saveImageMapToDataStore(DataStoreService.java:183)
at com.sparks.nirant.serviceImpl.AdminServiceImpl.addGallery(AdminServiceImpl.java:121)
at com.sparks.nirant.server.AdminController.doPost(AdminController.java:297)
请协助。