2017-07-26 89 views
3

我要插入的文件夹中的文件,在这个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

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

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

此外,注意到Files: insert

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

最后,另请参阅Migrating from Google Drive API v2了解更多信息。

+0

感谢你的帮助,在谷歌驱动器的文件夹没有扩展 但是,我找到了解决方案,它的工作,我没有做ParentReference()是正确的,我做它用错了地方 –