Upload a file with Rest API C# unity
Hi,
I need help on upload a file on Box.
IEnumerator Upload()
{
byte[] imagebyte = File.ReadAllBytes("C:/Users/harshit.gaur/Desktop/Test11.txt");
//Debug.Log("image " + imagebyte.ToString());
attributes.name = "Test11.txt";
attributes.parent.id = "166060886898";
attributes.content_created_at = DateTime.Now.ToString();
attributes.content_modified_at = DateTime.Now.ToString();
string attri = JsonUtility.ToJson(attributes);
List<IMultipartFormSection> form = new List<IMultipartFormSection>();
form.Add(new MultipartFormDataSection("attributes", attri, Encoding.UTF8, "application/json"));
form.Add(new MultipartFormFileSection("file", imagebyte, "Test11.txt", "application/octet-stream"));
UnityWebRequest www = UnityWebRequest.Post(uploadUrl, form);
www.SetRequestHeader("Content-Type", "multipart/form-data");
if (playerToken != "")
{
print("URL " + playerToken);
www.SetRequestHeader("Authorization", "Bearer " + playerToken);
}
yield return www.SendWebRequest();
if (www.isNetworkError || www.isHttpError)
{
Debug.Log(www.downloadHandler.text);
}
else
{
Debug.Log("Form upload complete! " + www.downloadHandler.text);
}
}
With this code i am getting response {"code":"bad_request","help_url":"http://developers.box.com/docs/#errors","status":400,"message":"the request was rejected because no multipart boundary was found","type":"error"}
Can anyone help what is missing in this above ?
Post is closed for comments.
Comments
0 comments