无法使用GCS客户端库

无法使用GCS客户端库

本文介绍了无法使用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(树林深邃而可爱。);
out.println(但我承诺保持。);
out.flush();
writeChannel.waitForOutstandingWrites();
writeChannel.write(ByteBuffer.wrap(And miles to go before I sleep。。getBytes()));
writeChannel.close();

当我查看日志时,我得到了这样的403错误

 服务器回复403,检查ACL是否在对象和存储桶上正确设置:
请求:POST https://storage.googleapis.com/ <存储桶名称> /<对象名称>
x-goog-resumable:start
x-goog-api-version:2
Content-Type:text / html
x-goog-acl:public-read

没有内容

响应:403与152字节的内容
Content-Type:application / xml; charset = UTF-8
内容长度:152
日期:2013年7月2日星期二14:10:02 GMT
服务器:HTTP上传服务器建立于Jun 28 2013 13:27:54 (1372451274)
X-Google-Cache-Control:remote-fetch
Via:HTTP / 1.1 GWA
<?xml version ='1.0'encoding ='UTF-8'?> < Error>< Code> AccessDenied< / Code>< Message> Access denied。< / Message>< Details> images2.solestruck.com< / Details>< / Error>

有人可以帮我解决这个问题。

解决方案

我有同样的问题。按照以下说明操作()

它适用于我。

I am trying to upload image/file to google cloud storage from my GAE application using new Gcs Client Library.

Here is the code snippet

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();

When i look into the logs i am getting 403 error like this

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
Content-Type: text/html
x-goog-acl: public-read

no content

Response: 403 with 152 bytes of content
Content-Type: application/xml; charset=UTF-8
Content-Length: 152
Date: Tue, 02 Jul 2013 14:10:02 GMT
Server: HTTP Upload Server Built on Jun 28 2013 13:27:54 (1372451274)
X-Google-Cache-Control: remote-fetch
Via: HTTP/1.1 GWA
<?xml version='1.0' encoding='UTF-8'?><Error><Code>AccessDenied</Code><Message>Access denied.</Message><Details>images2.solestruck.com</Details></Error>

Can someone help me in fixing this.

解决方案

I have the same problem. Follow instructions below (https://developers.google.com/appengine/docs/java/googlestorage/#Java_Prerequisites)

It works for me.

这篇关于无法使用GCS客户端库+ java将GAE项目中的文件上传到Google云存储的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

08-02 01:37