Google Cloud Storage File Upload - The requested page was not found. [404]

I am trying to upload a file to Google Cloud Storage using the Json API. I am sending a request below the url with the attached file.

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

But I get the requested page was not found. Error 404]. When I use the URL below, I can list the images stored in the bucket (just to make sure there are no access problems and the bucket name is correct).

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

I set the headers.

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

The following is a snippet of code.

        $.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);
        }
    });

Do I need to use a different URL? Or do I need another setting? Please, help.

+4
source share
1 answer

URL-, mybucket . jquery.ajax() , , , , &callback=foo - dataType: 'jsonp' &_=1474410231688, cache: false, curl . jqXHR, ?

0

Source: https://habr.com/ru/post/1653904/


All Articles