REST API - Using the Content-Type Multipart Method
1 min
you can use the multipart method with the following requests rest api add attachment request docid\ vhunqlitn6g7ya2f5eqzx rest api add attachment to subartifact request docid\ egmczsns7uzcipg2ed9s7 to add data using the multipart method, you must use boundary parameters for the data for more information on using multipartcontent , see http //www w3 org/protocols/rfc1341/7 2 multipart html http //www w3 org/protocols/rfc1341/7 2 multipart html example in c# { //call rest api var fetchrequest = (httpwebrequest)webrequest create(string concat(baseuri, "/", apicall)); fetchrequest headers add("authorization", “blueprinttoken” + “ “ + authenticationtoken); fetchrequest accept = "application/xml"; fetchrequest method = "post"; fetchrequest keepalive = true; fetchrequest credentials = system net credentialcache defaultcredentials; //start creating multipart boundary string boundary = " " + datetime now\ ticks tostring("x"); byte\[] boundarybytes = system text encoding ascii getbytes("\r\n " + boundary + "\r\n"); fetchrequest contenttype = "multipart/form data; boundary=" + boundary; using (stream rs = fetchrequest getrequeststream()) { //add starting boundary rs write(boundarybytes, 0, boundarybytes length); //add content headers (content disposition header) string headertemplate = "content disposition form data; name=\\"{0}\\"; filename=\\"{1}\\"\r\ncontent type {2}\r\n\r\n"; string header = string format(headertemplate, paramname, file, contenttype); byte\[] headerbytes = system text encoding utf8 getbytes(header); rs write(headerbytes, 0, headerbytes length); //add file using (var filestream = new filestream(file, filemode open, fileaccess read)) { var buffer = new byte\[4096]; int bytesread = 0; while ((bytesread = filestream read(buffer, 0, buffer length)) != 0) { rs write(buffer, 0, bytesread); } } //add last boundary byte\[] trailer = system text encoding ascii getbytes("\r\n " + boundary + " \r\n"); rs write(trailer, 0, trailer length); } //send request var webresponse = fetchrequest getresponse() as httpwebresponse; }