Google cloud platform 无法使用Google云存储POST对象XML API上载超过50KB的内容

Google cloud platform 无法使用Google云存储POST对象XML API上载超过50KB的内容,google-cloud-platform,google-cloud-storage,Google Cloud Platform,Google Cloud Storage,我已经创建了一个表单,用于使用PostObjectXMLAPI将文件上传到Google云存储 除了超过50KB的文件外,这一切正常。我已经在Google Chrome和Firefox上进行了测试 这是HTML <form id="upload-form" method="POST" role="search"> <div class="form-group"> <label class="c

我已经创建了一个表单,用于使用PostObjectXMLAPI将文件上传到Google云存储

除了超过50KB的文件外,这一切正常。我已经在Google Chrome和Firefox上进行了测试

这是HTML

    <form id="upload-form"
          method="POST"
          role="search">
      <div class="form-group">
        <label class="col-sm-2 control-label">File input</label>
        <div class="col-sm-10">
          <input type="file" class="filestyle"
                 name="file">
        </div>
      </div>
      <div class="form-group">
        <div class="col-sm-4 col-sm-offset-2">
          <button type="submit" class="btn btn-primary">Upload</button>
        </div>
      </div>
    </form>
这个端点/实验性的/上传的/签名的url创建了如下响应

    {
      "googleAccessId" : "xxxx",
      "policy" : "REDACTED",
      "signature" : "REDACTED",
      "successActionStatus" : "201",
      "url" : "https://storage.googleapis.com/my-bucket",
      "bucket" : "my-bucket",
      "key" : "path/file-name",
      "clientName" : null,
      "publicUrl" : "https://storage.googleapis.com/my-bucket/path/file-name"
    }
创建签名的代码如下所示

    try {
        byte[] policy = policyDocument.toJsonBytes();
        System.out.println(policyDocument.toJson());
        String encodedPolicy = BaseEncoding.base64().encode(policy);
        ServiceAccountCredentials cred = ServiceAccountCredentials
            .fromStream(new FileInputStream(googleCredentialsFile));
        byte[] signatureBytes = cred.sign(encodedPolicy.getBytes(Charsets.UTF_8));
        String signature = BaseEncoding.base64().encode(signatureBytes);
        info.setGoogleAccessId(cred.getAccount());
        info.setPolicy(encodedPolicy);
        info.setSignature(signature);
        info.setSuccessActionStatus(STATUS_CODE);
        info.setUrl(String.format(END_POINT_URL_FORMAT, info.getBucket()));
        return info;
    } catch (IOException e) {
        throw new RuntimeException(e);
    }
下面是政策文件的内容

  {
    "conditions": [
      {
        "success_action_status": "201"
      },
      {
        "bucket": "XXXXX"
      },
      {
        "key": "path/file-name"
      },
      [
        "content-length-range",
        0,
        1895825408
      ]
    ],
    "expiration": "2018-06-13T12:51:45.143+03:00"
  }
对于超过50KB的文件,我在这个主体中获得HTTP状态400

<?xml version="1.0" encoding="UTF-8"?>
<Error>
   <Code>InvalidArgument</Code>
   <Message>Invalid argument.</Message>
   <Details>Cannot create buckets using a POST.</Details>
</Error>

有没有人可以帮我上传超过50KB的内容?

我有GCP支持。我们能够使用基于的POST请求获得相同的错误消息,与文件大小无关

一旦我们将等价物更改为
“url”:https://storage.googleapis.com/my-bucket,通过添加对象:
“url”:https://storage.googleapis.com/my-bucket/my-file.ext“,

然后使用
POST
我们不断收到一些错误消息,因此我们将方法更改为
PUT
。然后它成功了

不工作卷曲请求:

curl -d @[FILENAME.EXT] @[JSONFILE.json] -X POST -H 'Authorization: Bearer [TOKEN]' http://[BUCKET_NAME].storage.googleapis.com/ 
curl -v H 'Authorization: Bearer [TOKEN]' -F upload=@[FILENAME.EXT] -X PUT http://[BUCKET_NAME].storage.googleapis.com/[FILENAME.EXT]
工作要求:

curl -d @[FILENAME.EXT] @[JSONFILE.json] -X POST -H 'Authorization: Bearer [TOKEN]' http://[BUCKET_NAME].storage.googleapis.com/ 
curl -v H 'Authorization: Bearer [TOKEN]' -F upload=@[FILENAME.EXT] -X PUT http://[BUCKET_NAME].storage.googleapis.com/[FILENAME.EXT]

我还要求根据所学到的经验改进文档

使您的文件字段成为表单的最后一个字段,即

  var frm = new FormData(this);
  var file_path = uploadForm.get("file");
  uploadForm.delete("file");
  uploadForm.append("file", file_path);
  ajax.send(uploadForm);

POST方法似乎只适用于对象,而不适用于bucket。请看XMLAPI的最新版本。可以使用PUT方法上载bucket,对于对象,可以使用POST。这就是为什么您收到
无法使用POST
错误创建bucket的原因。您是否定义如下的表单操作:?也许我遗漏了一些东西,但在你的代码中看不到。你也可以看到@Temu我已经编辑了问题并添加了HTML。实际上,我阅读了文档,甚至可以上传上面的代码,只要文件不超过50KB。这是如何绕过50KB限制的?这是专门针对GCP Bucket的情况。