在文件夹谷歌驱动器中插入文件

时间:2017-07-26 11:55:38

标签: vb.net file google-drive-api directory

我想在文件夹中插入文件,在此page中搜索后,我尝试这样做

有我的代码:

'folder creation
Dim dossier = New Google.Apis.Drive.v2.Data.File()
dossier.Title = dat_sauv.SelectedItem
dossier.MimeType = "application/vnd.google-apps.folder"
Dim rep = Service.Files.Insert(dossier)
rep.Fields = "id"

Dim ref As New ParentReference()
ref.Id = dossier.Id
MessageBox.Show(dossier.Id)
Dim file = rep.Execute()
' file creation
Dim f As New Google.Apis.Drive.v2.Data.File()
f.Title = fichier_txt.Text
f.Description = " fichier drive"
f.MimeType = "text/plain , image/jpeg"
Dim s As Integer
s = f.Id

Try
    Dim r = Service.Parents.Insert(ref, s).Execute()

Catch ex As Exception
    MessageBox.Show(ex.Message)
End Try

但错误是:

enter image description here

我无法解决此错误。 当我将s的类型更改为字符串时,错误消息是:

enter image description here

1 个答案:

答案 0 :(得分:1)

AFAIK,如果不支持文件格式,导入操作将返回400错误。有了这个,您可能想尝试specifying file names and extensions

  

在使用API​​插入文件时,应在title属性中指定文件扩展名。例如,插入JPEG文件的操作应在元数据中指定"name": "cat.jpg"之类的内容。

另请参阅Files: insert

  

使用files.insert创建快捷方式的应用必须指定MIME类型application/vnd.google-apps.drive-sdk

最后,另请参阅Migrating from Google Drive API v2了解详情。