2017-08-25 140 views
1

我想使用curl将一个zip文件上传到Google驱动器帐户。使用卷曲将zip文件上传到谷歌驱动器

文件成功上传,但文件名未得到更新。它以默认文件名即“无标题”上传。

我正在使用下面的命令。

curl -k -H "Authorization: Bearer cat /tmp/token.txt" -F "metadata={name : 'backup.zip'} --data-binary "@backup.zip" https://www.googleapis.com/upload/drive/v2/files?uploadType=multipart 
+0

你需要用卷曲来做吗?如果不这样做,则可以使用'gdrive'命令(http://olivermarshall.net/how-to-upload-a-file-to-google-drive-from-the-command-line/) –

+0

正在运行这在没有空间安装gdrive的路由器上。因此,使我的自定义脚本做到这一点 –

+0

看看这个评论 这个论坛:https://gist.github.com/deanet/3427090#gistcomment-1253229。也许你需要根据这篇文章设置一些变量。 –

回答

1

您可以使用Drive API v3上传zip文件。修改的卷曲代码如下。

curl -X POST -L \ 
    -H "Authorization: Bearer `cat /tmp/token.txt`" \ 
    -F "metadata={name : 'backup.zip'};type=application/json;charset=UTF-8" \ 
    -F "[email protected];type=application/zip" \ 
    "https://www.googleapis.com/upload/drive/v3/files?uploadType=multipart" 

为了使用这个,请在​​范围中包括https://www.googleapis.com/auth/drive

+0

谢谢Ton Tanaike !!!你摇滚..顺便说一下,V2也使用相同的代码 –

+0

@nbuser欢迎。也谢谢你。 – Tanaike

+0

可否请您评论如何上传具有相同上述代码的特定文件夹中的文件。谢谢。 –

相关问题