Google Drive API JavaScript - 插入文件 [英] Google Drive API JavaScript - Insert file

查看:155
本文介绍了Google Drive API JavaScript - 插入文件的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我试图插入Drive文件。
我创建了auth,它的工作原理是正确的:)

但是当我尝试从JS创建(插入)一个新文件时,它会创建一个,而是名为无标题的文件,根本没有扩展名。 (我在我的文件系统上有一个同步文件夹,这是同样的事情)。



我的代码是这样的:

 函数createNewFile(){
gapi.client.load('drive','v2',function(){
var request = gapi.client .drive.files.insert($ b $title:cat.jpg,
mimeType:image / jpeg,
description:某些
)};
request.execute(function(resp){console.log(resp);});
});
}

任何有关错误的想法?
我可以从我的驱动器列出来自JS的文件,并且这段代码创建了这个untitled并且没有扩展文件。

解决方案

<我有这样的工作:

 函数createNewFile(){

gapi.client。 load('drive','v2',function(){

var request = gapi.client.request({$ b $'path':'/ drive / v2 / files',
'method':'POST',
'body':{
title:cat.jpg,
mimeType:image / jpeg,
description:某些
}
});

request.execute(function(resp){console.log(resp);});
});
}

请记住,如果标题为 cat的文件.jpg 已存在,此请求将创建另一个具有相同标题的文件,因为Google云端硬盘中的文件具有唯一的文件ID,因此内部引用该文件。


I'm trying to "insert" a Drive file. I've made the auth and it works right :)

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).

My code is this:

 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); });
    });
 }

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.

解决方案

I have that working like this:

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); });
   });
}

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 - 插入文件的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆