問(wèn)題描述
我正在嘗試插入"一個(gè)云端硬盤(pán)文件.我已經(jīng)進(jìn)行了身份驗(yàn)證,它工作正常:)
I'm trying to "insert" a Drive file. I've made the auth and it works right :)
但是當(dāng)我嘗試從 JS 創(chuàng)建(插入)一個(gè)新文件時(shí),它會(huì)創(chuàng)建一個(gè)名為Untitled"的文件,根本沒(méi)有擴(kuò)展名.(我的文件系統(tǒng)上有一個(gè)同步文件夾,也是一樣的).
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); });
});
}
知道什么是錯(cuò)的嗎?我可以從 JS 的驅(qū)動(dòng)器中列出文件,這段代碼創(chuàng)建了這個(gè)無(wú)標(biāo)題"并且沒(méi)有擴(kuò)展文件.
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); });
});
}
請(qǐng)注意,如果標(biāo)題為 cat.jpg
的文件已存在,則此請(qǐng)求將創(chuàng)建另一個(gè)具有相同標(biāo)題的文件,因?yàn)?Google 云端硬盤(pán)中的文件具有唯一的文件 ID,內(nèi)部引用這些文件 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.
這篇關(guān)于Google Drive API JavaScript - 插入文件的文章就介紹到這了,希望我們推薦的答案對(duì)大家有所幫助,也希望大家多多支持html5模板網(wǎng)!