Google 云存储文件上传 - 找不到请求的页面。【404】

Lal*_*ane 5 google-cloud-storage google-cloud-platform

我正在尝试使用 Json API 将文件上传到 Google Cloud Storage。我将请求连同文件附件发布到以下网址。

https://www.googleapis.com/upload/storage/v1/b/mybucket/o?uploadType=media&name=solarsystemlrg.png
Run Code Online (Sandbox Code Playgroud)

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

https://www.googleapis.com/storage/v1/b/mybucket/o
Run Code Online (Sandbox Code Playgroud)

我已经设置了标题。

'Authorization' :'Bearer ' + accessToken,
'Content-Type' : contentType,
'Content-Length' : inputFile.size
Run Code Online (Sandbox Code Playgroud)

请找到下面的代码片段。

        $.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);
        }
    });
Run Code Online (Sandbox Code Playgroud)

我需要使用不同的 URL 吗?或者还需要什么其他设置吗?请帮忙。

Nat*_*ing 1

只要您将其替换mybucket为您的实际存储桶名称,这就是正确的 URL。读完后,我通过添加、 due to和becausejquery.ajax()来模拟我认为的行为,并通过 和 发出请求,生成一个带有有效回调的有效对象。您可以记录整个内容以查看更多状态吗?&callback=foodataType: 'jsonp'&_=1474410231688cache: falsecurljqXHR