Warning: file_get_contents(/data/phpspider/zhask/data//catemap/9/google-cloud-platform/3.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Google cloud platform CORS标头在PUT请求中存在,但在OPTIONS请求中不存在_Google Cloud Platform_Cors_Google Cloud Storage_Google Api Nodejs Client_Pre Signed Url - Fatal编程技术网

Google cloud platform CORS标头在PUT请求中存在,但在OPTIONS请求中不存在

Google cloud platform CORS标头在PUT请求中存在,但在OPTIONS请求中不存在,google-cloud-platform,cors,google-cloud-storage,google-api-nodejs-client,pre-signed-url,Google Cloud Platform,Cors,Google Cloud Storage,Google Api Nodejs Client,Pre Signed Url,我有一个具有以下CORS配置的Google云存储桶: [ { "origin": ["http://localhost:8080"], "responseHeader": [ "Content-Type", "Access-Control-Allow-Origin", "Origin"],

我有一个具有以下CORS配置的Google云存储桶:

[
    {
      "origin": ["http://localhost:8080"],
      "responseHeader": [
        "Content-Type",
        "Access-Control-Allow-Origin",
        "Origin"],
      "method": ["GET", "HEAD", "DELETE", "POST", "PUT", "OPTIONS"],
      "maxAgeSeconds": 3600
    }
]
我正在生成带有以下代码的签名URL:

let bucket = storage.bucket(bucketName);
let file = bucket.file(key);

const options = {
    version: "v4",
    action: "write",
    expires: Date.now() + 15 * 60 * 1000, // 15 minutes
    contentType: "application/zip"
};

let url = await file.getSignedUrl(options))[0];
对于我的请求,我使用以下标题:

Origin: http://localhost:8080
Content-Type: application/zip
当我尝试使用PUT请求上传数据时,一切正常,我得到了包含我的源代码的Access Control Allow Origin标头。但是,当我使用完全相同的头执行选项请求时,它无法返回Access Control Allow Origin头。我尝试了许多对CORS配置的修改,但没有一个能像这样工作:

  • 将原点更改为
    *
  • 答案和评论中描述的不同变化
  • 中描述的不同变化

注意,如上所述,您不应在CORS配置中指定选项,并注意云存储仅支持XML API的
DELETE、GET、HEAD、POST、PUT
和JSON API的
DELETE、GET、HEAD、PATCH、POST、PUT
。因此,我相信您使用
选项所经历的应该是预期行为。

我在同事的帮助下解决了自己的问题,当我在Postman中测试该功能时,CORS标头没有作为对
选项
请求的响应发送,因为请求缺少
访问控制请求方法
标头。当我添加此标题时,效果很好。

找到解决方案做得很好!你能?它将使它更为明显,并在您找到解决方案时帮助有相同问题的人。谢谢谢谢你的提醒,它昨天告诉我,我只能明天(也就是今天)接受。