Google Drive API JavaScript - Insert file(Google Drive API JavaScript - 插入文件)
问题描述
我正在尝试插入"一个云端硬盘文件.我已经进行了身份验证,它工作正常:)
I'm trying to "insert" a Drive file. I've made the auth and it works right :)
但是当我尝试从 JS 创建(插入)一个新文件时,它会创建一个名为Untitled"的文件,根本没有扩展名.(我的文件系统上有一个同步文件夹,也是一样的).
But when I try to create (insert) a new file from JS, it creates one, but a file named "Untitled" with no extension at all. (I have a sync folder on my file system, and it is the same thing).
我的代码是这样的:
function createNewFile( ) {
gapi.client.load('drive', 'v2', function() {
var request = gapi.client.drive.files.insert ( {
"title" : "cat.jpg",
"mimeType" : "image/jpeg",
"description" : "Some"
} );
request.execute(function(resp) { console.log(resp); });
});
}
知道什么是错的吗?我可以从 JS 的驱动器中列出文件,这段代码创建了这个无标题"并且没有扩展文件.
Any idea about what is wrong? I can list files from my drive from JS, and this code creates this "untitled" and no extensioned file.
推荐答案
我有这样的工作:
function createNewFile( ) {
gapi.client.load('drive', 'v2', function() {
var request = gapi.client.request({
'path': '/drive/v2/files',
'method': 'POST',
'body':{
"title" : "cat.jpg",
"mimeType" : "image/jpeg",
"description" : "Some"
}
});
request.execute(function(resp) { console.log(resp); });
});
}
请注意,如果标题为 cat.jpg
的文件已存在,则此请求将创建另一个具有相同标题的文件,因为 Google 云端硬盘中的文件具有唯一的文件 ID,内部引用这些文件 ID.
Bear in mind that if a file with title cat.jpg
already exists, this request will create another file with the same title, since files in Google Drive have unique file IDs by which are referred internally.
这篇关于Google Drive API JavaScript - 插入文件的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持编程学习网!
本文标题为:Google Drive API JavaScript - 插入文件


- 我不能使用 json 使用 react 向我的 web api 发出 Post 请求 2022-01-01
- 如何显示带有换行符的文本标签? 2022-01-01
- 在不使用循环的情况下查找数字数组中的一项 2022-01-01
- 为什么悬停在委托事件处理程序中不起作用? 2022-01-01
- 从原点悬停时触发 translateY() 2022-01-01
- 为什么我的页面无法在 Github 上加载? 2022-01-01
- 如何调试 CSS/Javascript 悬停问题 2022-01-01
- 是否可以将标志传递给 Gulp 以使其以不同的方式 2022-01-01
- 如何向 ipc 渲染器发送添加回调 2022-01-01
- 使用 iframe URL 的 jQuery UI 对话框 2022-01-01