小编use*_*452的帖子

无法使用GCS客户端库+ java将文件从GAE项目上传到Google云存储

我正在尝试使用新的Gcs客户端库从我的GAE应用程序上传图像/文件到谷歌云存储.

这是代码片段

GcsService gcsService = GcsServiceFactory.createGcsService(new RetryParams.Builder()
          .initialRetryDelayMillis(10)
          .retryMaxAttempts(10)
          .totalRetryPeriodMillis(15000)
          .build());
GcsFilename filename = new GcsFilename(BUCKETNAME, FILENAME);
GcsFileOptions options = new GcsFileOptions.Builder().mimeType("text/html").acl("public-read").build();
GcsOutputChannel writeChannel = gcsService.createOrReplace(filename,options);           
PrintWriter out = new PrintWriter(Channels.newWriter(writeChannel, "UTF8"));
out.println("The woods are lovely dark and deep.");
out.println("But I have promises to keep.");
out.flush();
writeChannel.waitForOutstandingWrites();
writeChannel.write(ByteBuffer.wrap("And miles to go before I sleep.".getBytes()));
writeChannel.close();
Run Code Online (Sandbox Code Playgroud)

当我查看日志时,我收到403错误

Server replied with 403, check that ACLs are set correctly on the object and bucket:
Request: POST https://storage.googleapis.com/<bucket name>/<object name>
x-goog-resumable: start
x-goog-api-version: 2 …
Run Code Online (Sandbox Code Playgroud)

java google-app-engine google-cloud-storage

3
推荐指数
1
解决办法
3108
查看次数