javascript - 在Angular 4中将文件上传到Google驱动器中的特定文件夹
问题描述
我正在尝试将文件上传到特定文件夹,但我无法做到。上传工作正常,但它没有将文件放在特定文件夹中。
我正在尝试使用 google drive rest 版本 3 进行可恢复上传。
假设我已经有一个文件夹 ID。
首先获取上传 URI:
uploadFileToDrive(name: string, content: string): Promise<Object> {
const url = `https://www.googleapis.com/upload/drive/v3/files?uploadType=resumable`;
const accessToken = localStorage.getItem('accessToken');
let headers = new Headers({
'Content-Type': 'application/json; charset=UTF-8',
'Authorization': 'Bearer ' + accessToken,
});
let options = new RequestOptions({ headers: headers }); // Create a request option
return this.http
.post(url, { name: name, role: 'reader', type: 'anyone', 'parents': [{"id":parentId}] }, options)
.toPromise()
.then(response => this.gDriveUploadFile(content, response.headers.get('location')));
}
第二次上传媒体:
gDriveUploadFile(file, url): Promise<any> { //file and url we got from first func
console.log(file + " "+ url );
const accessToken = localStorage.getItem('accessToken');
let headers = new Headers({
'Authorization': 'Bearer ' + accessToken,
'Content-Type': 'application/json; charset=UTF-8',
'X-Upload-Content-Type': file.type ,
});
let options = new RequestOptions({ headers: headers }); // Create a request option
return this.http.post(`${url}`, file, options) //call proper resumable upload endpoint and pass just file as body
.toPromise()
}
另外,我想知道如何使用 google rest API 以 angular 创建一个文件夹。
解决方案
推荐阅读
- xml - 用于检查 XML 文件的 PowerShell 命令
- python - 对齐现有 Excel 工作表中的一列
- python-3.x - 股票投资组合跟踪器,循环发行
- javascript - 我无法使用 Axios(React、Node.JS)从用户上传的文件中发布 FormData 对象
- c - 为什么 fgets 在循环中将 char 转换为 int 后会跳过输入?
- javascript - 当用户更改时,消息不是来自网络套接字
- python - “验证您的防火墙或防病毒软件是否允许 Python 进程打开系统中的端口” Spyder 问题
- flutter - 颤振音频播放器音频不播放
- flutter - 颤动着色掩码小部件未在字符级别显示渐变
- three.js - 如何在 Three.js 中渲染期间更改动画速度