简体   繁体   English

Jclouds分段上传到Google Cloud Storage失败,出现400错误请求

[英]Jclouds multipart upload to Google Cloud Storage failing with 400 Bad Request

I am building an application that uses Jclouds (version 2.1.0) to access Google Cloud Storage and upload/download files. 我正在构建一个使用Jclouds(版本2.1.0)访问Google Cloud Storage并上传/下载文件的应用程序。 I am encountering an issue with multipart uploads. 我遇到了分段上传问题。 Not sure if I am doing something wrong, or if this is a bug. 不知道我是在做错什么,还是这是个错误。

What I am seeing is whenever I do a multipart upload, I get a "400 Bad Request" response. 我看到的是,每当分段上传时,都会收到“ 400错误的请求”响应。 Here is the code I am using to upload: 这是我用来上传的代码:

String fileContents = Files.toString(new File("google_creds.json"), Charset.defaultCharset());

Supplier<Credentials> credentialSupplier = new GoogleCredentialsFromJson(fileContents);

Iterable<Module> modules = ImmutableSet.<Module>of(
        new SLF4JLoggingModule());

BlobStoreContext context = ContextBuilder.newBuilder("google-cloud-storage")
        .credentialsSupplier(credentialSupplier)
        .modules(modules)
        .buildView(BlobStoreContext.class);

BlobStore client = context.getBlobStore();

byte[] testBytes = new byte[102400];

Blob blob = client.blobBuilder("testupload").payload(testBytes)
        .contentLength(testBytes.length).build();


// Multipart upload fails
 client.putBlob("filecatalyst-unit-tests", blob, multipart());

And here is the logging output that I see: 这是我看到的日志记录输出:

>> "{"sourceObjects":[{"name":"3fda0043-e340-4ccb-a582-9e3b78cf85e1_00000001","generation":1520026856033315,"objectPreconditions":{"ifGenerationMatch":1520026856033315}}],"destination":{"name":"testupload","size":102400,"contentType":"application/unknown","storageClass":"STANDARD","metadata":{}}}"
>> POST https://www.googleapis.com/storage/v1/b/filecatalyst-unit-tests/o/testupload/compose HTTP/1.1
>> Accept: application/json
>> Authorization: Bearer ***********************
>> Content-Type: application/json
>> Content-Length: 293
<< HTTP/1.1 400 Bad Request
<< Alt-Svc: hq=":443"; ma=2592000; quic=51303431; quic=51303339; quic=51303338; quic=51303337; quic=51303335,quic=":443"; ma=2592000; v="41,39,38,37,35"
<< Server: UploadServer
<< X-GUploader-UploadID: AEnB2UpqKslm87V4wto81YsNphtPFtybHjWgffGAC3XPE-xQAXSjDldst5s5nuWPyhXjEGOwWE5kDETjNA1EedbuEw9Vbe8CtA
<< Vary: X-Origin
<< Vary: Origin
<< Date: Fri, 02 Mar 2018 21:40:56 GMT
<< Content-Type: application/json; charset=UTF-8
<< Content-Length: 178
<< "{[\n]"
<< " "error": {[\n]"
<< "  "errors": [[\n]"
<< "   {[\n]"
<< "    "domain": "global",[\n]"
<< "    "reason": "invalid",[\n]"
<< "    "message": "Invalid argument"[\n]"
<< "   }[\n]"
<< "  ],[\n]"
<< "  "code": 400,[\n]"
<< "  "message": "Invalid argument"[\n]"
<< " }[\n]"
<< "}[\n]"

Here is a formatted version of the JSON body for the compose request: 这是用于撰写请求的JSON正文的格式化版本:

{  
   "sourceObjects":[  
      {  
         "name":"83116375-0ba1-4d1a-aec3-8dd29dab0da9_00000001",
         "generation":1520263556434885,
         "objectPreconditions":{  
            "ifGenerationMatch":1520263556434885
         }
      }
   ],
   "destination":{  
      "name":"testupload",
      "size":33554432,
      "contentType":"application/unknown",
      "storageClass":"STANDARD",
      "metadata":{  

      }
   }
}

Have tried with varying size files, and I get the same result. 尝试过使用不同大小的文件,并且得到相同的结果。 If I do not use multipart upload, it works fine. 如果我不使用分段上传,则效果很好。

JCLOUDS-1389跟踪了此问题,jclouds 2.1.1和2.2.0将包含此修复程序。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 400 分段文件上传错误请求 - 400 Bad Request on Multipart File Upload 使用 HttpURLConnection 的 Android 分段文件上传 - 400 错误请求错误 - Android Multipart File Upload using HttpURLConnection - 400 Bad Request Error Google Drive REST API可恢复上传返回400错误请求 - Google Drive REST API Resumable upload returnin 400 Bad Request 适用于Java的Cloud Storage API客户端库:-400错误的请求:“错误”:“ unauthorized_client” - Cloud Storage API Client Library for Java: - 400 Bad Request : “error” : “unauthorized_client” 向Spring MVC Controller发送多部分请求时出现400错误的请求 - 400 Bad Request When Send Multipart Request To Spring MVC Controller 使用Webflux和Spring Boot与Google云存储上传MultiPart文件时出现UnsupportedOperationException - UnsupportedOperationException with MultiPart file upload using Webflux and Spring Boot with Google Cloud Storage Box API文件上传400错误的请求 - Box API file upload 400 bad request 改造图像上传返回错误请求400 - Retrofit image upload returns bad request 400 将对象上传到Google Cloud Storage - Upload objects to Google Cloud Storage Google Places API:错误400 :(错误请求) - Google Places API: Error 400: (Bad Request)
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM