0

I'm trying to upload a file with some metadata to google drive

heres my code basically:

Sub DriveMultiUpload(Bytes As Byte(), Name As String)
        SetAuthHeaders("https://www.googleapis.com/auth/drive")
        Dim mp = New MultipartFormDataContent
        mp.Add(New StringContent(Name), "name")
        mp.Add(New ByteArrayContent(Bytes))
        Dim pb = mp.ReadAsByteArrayAsync.Result
        Headers("Content-Type") = "multipart/related"
        Dim response As Byte()
        Dim ret = New WebInfo(Of String)
        Try
            response = UploadData("https://www.googleapis.com/upload/drive/v3/files?uploadType=multipart", "POST", pb)
        Catch ex As WebException
            If ex.Response IsNot Nothing Then ret.Result = New StreamReader(ex.Response.GetResponseStream).ReadToEnd
        End Try
    End Sub

The error I'm getting is:

Bad content type. Please use multipart.

[BTW, I tried debugging in Fiddler, but

  1. this request doesnt show up,
  2. when Fiddler is open, the response is empty alltogether]

As you see in the code, i AM using multipart as the content-type

What i find odd though is that as soon as the uploaddata returns, the Headers does not contain any content-type at all anymore, so maybe this might be the issue?

please advise

Linda Lawton - DaImTo
  • 106,405
  • 32
  • 180
  • 449
Yisroel M. Olewski
  • 1,560
  • 3
  • 25
  • 41

1 Answers1

0

the answer seems to be simply not to use the MultipartFormDataContent

rather i based on this code here https://stackoverflow.com/a/29118333/240742

works like a charm

Yisroel M. Olewski
  • 1,560
  • 3
  • 25
  • 41