0
votes

I have BOX account and in API document

curl https://upload.box.com/api/2.0/files/content \ -H "Authorization: Bearer ACCESS_TOKEN" \ -F filename=@FILE_NAME \ -F parent_id=PARENT_FOLDER_ID

I am stuck with this filename and parent_id how to pass the filename and parent_id

i have tried lots of way, but nothing is working for me.

Following is the code:

        httpWReq.Method = "POST";
        httpWReq.Headers.Add("Authorization", "Bearer ");
        httpWReq.ContentType = "multipart/form-data";


        //{\"parent_id\":\""+parentID +"\"}

        //byte[] file = File.ReadAllBytes(postData);

        httpWReq.ContentLength = data.Length;

        using (Stream reqStream = httpWReq.GetRequestStream())
        {
            reqStream.Write(data, 0, data.Length);
                //reqStream.Close();
        }
        using (HttpWebResponse response = (HttpWebResponse)httpWReq.GetResponse())
        {
            //Console.WriteLine("HTTP/{0} {1} {2}", response.ProtocolVersion, (int)response.StatusCode, response.StatusDescription);
            response.Close();

        }

Need Help

Thanks in Advance

1
Hi Vaibhav, can you include some of the code that you've tried? Thanks! - John Hoerr
Hi @JohnHoerr i am not able to pass the File and the parentFolderID it throw bad request error. - Vaibhav Brahme

1 Answers

1
votes

Vaibhav,

Please see example of how official Box C# SDK is doing upload: https://github.com/box/box-windows-sdk-v2/blob/master/Box.V2/Managers/BoxFilesManager.cs

Is there any reason why you don't want to use Box Windows SDK?