【发布时间】: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