【问题标题】:Google Cloud Storage File Upload - Requested page not found. [404]Google 云存储文件上传 - 未找到请求的页面。 [404]
【发布时间】:2016-09-07 12:09:49
【问题描述】:

我正在尝试使用 Json API 将文件上传到 Google Cloud Storage。我将请求与文件附件一起发布到下面的 url。

https://www.googleapis.com/upload/storage/v1/b/mybucket/o?uploadType=media&name=solarsystemlrg.png

但我收到未找到请求的页面。 [404] 错误。当我使用下面的 Url 时,我可以列出存储在存储桶中的图像(只是为了确保没有访问问题并且存储桶名称正确)。

https://www.googleapis.com/storage/v1/b/mybucket/o

我已经设置了标题。

'Authorization' :'Bearer ' + accessToken,
'Content-Type' : contentType,
'Content-Length' : inputFile.size

请在下面找到代码sn-p。

        $.ajax({
        url: targetUrl,
        headers: reqHeaders,
        type: 'POST',
        data: reqFormWithDataFile,
        async: false,
        cache: false,
        dataType: 'jsonp',
        useDefaultXhrHeader: false,
        processData: false,
        success: function (response) {

                alert('File Upload Successful');

        },
        error: function (jqXHR, exception) {
            var msg = '';
            if (jqXHR.status === 0) {
                msg = 'Not connect.\n Verify Network.';
            } else if (jqXHR.status == 404) {
                msg = 'Requested page not found. [404]';
            } else if (jqXHR.status == 500) {
                msg = 'Internal Server Error [500].';
            } else if (exception === 'parsererror') {
                msg = 'Requested JSON parse failed.';
            } else if (exception === 'timeout') {
                msg = 'Time out error.';
            } else if (exception === 'abort') {
                msg = 'Ajax request aborted.';
            } else {
                msg = 'Uncaught Error.\n' + jqXHR.responseText;
            }
            alert(msg);
        }
    });

我需要使用不同的网址吗?或者是否需要其他设置?请帮忙。

【问题讨论】:

    标签: google-cloud-storage google-cloud-platform


    【解决方案1】:

    这是正确的 URL,只要您将 mybucket 替换为您的实际存储桶名称即可。在阅读了jquery.ajax() 之后,我通过添加&callback=foo 来模拟我认为的行为,由于dataType: 'jsonp'&_=1474410231688 因为cache: false,并通过curl 发出了请求,并产生了一个有效的对象一个有效的回调。您可以记录整个jqXHR 以查看更多状态吗?

    【讨论】:

      猜你喜欢
      • 2016-10-08
      • 2021-07-04
      • 1970-01-01
      • 2014-02-16
      • 1970-01-01
      • 1970-01-01
      • 2017-05-04
      • 2022-01-04
      • 1970-01-01
      相关资源
      最近更新 更多