Zied.M Zied.M - 1 year ago 176
Vb.net Question

insert file in folder google drive

I want to insert file in folder, after searching in this page , i try to do it

there is my code :

'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
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

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

Catch ex As Exception
End Try

but the error is :

enter image description here

and i can't resolve this error.
and when i change the type of s to string , the error message is :

enter image description here

Answer Source

AFAIK, import operations will return a 400 error if the file format is not supported. With this, you may want to try specifying file names and extensions.

Apps should specify a file extension in the title property when inserting files with the API. For example, an operation to insert a JPEG file should specify something like "name": "cat.jpg" in the metadata.

Also, noted in Files: insert,

Apps creating shortcuts with files.insert must specify the MIME type application/vnd.google-apps.drive-sdk.

Lastly, see also Migrating from Google Drive API v2 for more information.

Recommended from our users: Dynamic Network Monitoring from WhatsUp Gold from IPSwitch. Free Download