我想在文件夹中插入文件,在此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
但错误是:
我无法解决此错误。 当我将s的类型更改为字符串时,错误消息是:
答案 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了解详情。