jquery - Google Drive API 在可恢复上传时返回意外结果
问题描述
我正在尝试遵循Google 的Google Drive API 交互文档,特别是执行可恢复上传。我希望能够上传更大的 50MB+ 图像文件,以及修改上传文件在 Google Drive 中的描述以包含一些用户输入的文本。
我能够毫无问题地执行登录/身份验证。/token
我对 OAuth2端点运行 jQuery AJAX 调用,它为我提供了一个有效的access_token
,然后我可以使用它来直接调用 API。
然后,我根据文档对端点进行 AJAX 调用/files?uploadType=resumable
,将 HTTP 标头设置为包含access_token
,设置Content-Type
,等等。我还包括元数据,在这种情况下,它是新上传的图像文件的预期名称。
但是,我从 API 得到的响应令人困惑。它给了我一个status
200,根据文档,这是预期的响应,但返回的statusText
读数为"parsererror"
.
根据 Google 文档,我应该收到location
一串可恢复会话 URI,然后我可以将其用作 PUT 请求的端点,其中我将文件的数据包含在请求正文中。但是,在我收到的对象中,我没有看到任何location
预期的字符串或 URI。
任何帮助将不胜感激。这是返回令人困惑的对象的 jQuery AJAX 调用:
function fileUpload() {
var metadata = { "name" : "New Image" };
$.ajax({
type: "POST",
beforeSend: function(request) {
request.setRequestHeader("Authorization", "Bearer" + " " + localStorage.getItem("accessToken"));
request.setRequestHeader("Content-Type", "application/json; charset=UTF-8");
request.setRequestHeader("X-Upload-Content-Type", new_mime_type);
request.setRequestHeader("X-Upload-Content-Length", new_file_size);
},
cache: false,
dataType: "json",
data: JSON.stringify(metadata),
url: "https://www.googleapis.com/upload/drive/v3/files?uploadType=resumable",
success: function(data) {
console.log("Resumable upload POST call success. Returned data:");
console.log(data);
// Do a second $.ajax POST call here...?
},
error: function(data) {
console.log("Resumable upload POST call error. Returned data:");
console.log(data);
}
});
}
解决方案
推荐阅读
- python - 使用十六进制转义打印整个字符串,包括可打印字符
- redux - 如何在 redux store 中显示更新后的状态
- go - 在循环内创建 JWT 令牌时在 jwt-go 中获取相同的令牌
- module - 如何将特征的实现拆分为多个文件?
- python - 我在 settings.py 上实现了电子邮件设置,但是当我提交表单时它不起作用
- python - 删除包含 NaN 的 Pandas Dataframe 的前导行
- php - 可访问的敏感 URL
- android - 运行我的项目时显示此消息“Android 资源链接失败”
- c# - 如何反序列化 IPGeoLocation API 返回的 json 并在 .chtml 视图中使用
- c - C 编程中的 Malloc - 不兼容的指针类型