我尝试将文件保存到Google App Engine并遵循其文档,但不断在CreateOrReplace方法行上获取NullPointerException。已经发现gcsService已经创建了。有什么想法吗?
public String getFileUrl(MultipartFile file) throws CustomException {
String unique = UUID.randomUUID().toString();
String fileName = unique + ".jpeg";
GcsFilename gcsFilename = new GcsFilename("MY_BUCKET", fileName);
try {
GcsOutputChannel outputChannel = GcsServiceFactory.createGcsService().createOrReplace(gcsFilename, GcsFileOptions.getDefaultInstance());
copy(file.getInputStream(), Channels.newOutputStream(outputChannel));
} catch (IOException e) {
e.printStackTrace();
}
ImagesService imagesService = ImagesServiceFactory.getImagesService();
ServingUrlOptions options = ServingUrlOptions.Builder
.withGoogleStorageFileName("/gs/MY_BUCKET/" + fileName)
.secureUrl(true);
return imagesService.getServingUrl(options);
}
包含依赖:
<dependency>
<groupId>com.google.appengine.tools</groupId>
<artifactId>appengine-gcs-client</artifactId>
<version>0.7</version>
</dependency>
获得:
RetryHelper(32.34 s, 6 attempts, com.google.appengine.tools.cloudstorage.GcsServiceImpl$1@74c3f0b0): Too many failures, giving up
日志中有例外:
c.g.a.tools.cloudstorage.RetryHelper : RetryHelper(1.386 s, x attempts, com.google.appengine.tools.cloudstorage.GcsServiceImpl$1@6bd1dbe9): Attempt #x failed [java.io.IOException: java.lang.NullPointerException], sleeping for x ms
提前致谢!
修改
在com.google.apphosting.api上找到ApiProxy类
public static ApiProxy.Delegate getDelegate() {
return delegate;
}
返回NULL。
有什么想法吗?