2
votes

I'm trying to upload an image to a Google API. I'm using the .net WebClient.UploadFile. When I do the upload the request includes a Content-Type multipart/form-data;boundary= in the request and I'm getting the following error.

"Content-Type multipart/form-data;boundary=---------------------8d0738def5b9322 is not a valid input type"

Is there any way to remove this from the request or do I need to used a different upload method?

 var client = new WebClient();
 client.Headers.Add("Authorization", "Bearer " + _accessToken);
 client.Headers.Add("GData-Version", "2");
 client.Headers.Add("X-GData-Key", "key=" + _developerKey);
 client.Headers.Add("Content-Type", "image/jpeg");
 client.UploadFile(URL_PROFILE_UPLOAD_FEED.Replace("default", channelId), filePath);

Request format required by documentation.

POST /feeds/api/partners/default/images/IMAGE_TYPE HTTP/1.1 Host: uploads.gdata.youtube.com Content-Type: image/jpeg Authorization: Bearer ACCESS_TOKEN GData-Version: 2 X-GData-Key: key=DEVELOPER_KEY

BINARY_FILE_DATA

1
Try UploadData method of WebClient instead of UploadFile.Vladimir
@VladimirFrolov That did it. If you want to post that as an answer I'll mark it.NullReference

1 Answers

2
votes

You should use UploadData method of WebClient class instead of UploadFile.