I am trying to upload a file to box based on the api here: https://developers.box.com/docs/#files-upload-a-file, and I always get a "bad request" error.
Where is the problem?
url = https://upload.box.com/api/2.0/files/content
data = {"name":"1.jpg","parent":{"id":"0"}}
private Stream postToUrl(string url, string data)
{
WebRequest request = WebRequest.Create(url);
request.Method = WebRequestMethods.Http.Post;
byte[] byteArray = Encoding.UTF8.GetBytes(data);
request.ContentType = "multipart/form-data";
request.ContentLength = byteArray.Length;
request.Headers.Add("Authorization", "Bearer " + AccessToken);
Stream dataStream = request.GetRequestStream();
dataStream.Write(byteArray, 0, byteArray.Length);
dataStream.Close();
WebResponse response = request.GetResponse();
dataStream = response.GetResponseStream();
return dataStream;
}
I also tried to use the url: https://upload.box.com/api/2.0/files/content?access_token=AccessToken
instead of the Token inside the header
name
andparent
attributes? – tufelkinder