我正在尝试使用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请找到下面的代码片段。
$.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);
}
});我需要使用不同的URL吗?或者是否需要任何其他设置?请帮帮忙。
发布于 2016-09-21 06:32:17
只要将mybucket替换为实际的存储桶名称,这就是正确的URL。在阅读完jquery.ajax()之后,我模拟了我认为的行为,添加了&callback=foo,由于dataType: 'jsonp'和&_=1474410231688因为cache: false,并通过curl发出了请求,并生成了一个具有有效回调的有效对象。您可以记录整个jqXHR以查看更多状态吗?
https://stackoverflow.com/questions/39369600
复制相似问题