I am trying to invoke an API which accepts request with form-data parameters, one of the parameter is a file , which can be of any type(.pdf/.jpg/.doc). When I try to pass the path of the file as value in parameters, I get an error from the API - the request was rejected because no multipart boundary was found.
When I try to send the file as an attachment , the file is not received in the expected format, instead it is received as application/octet-stream.
Request to please suggest options to send the file using the HTTP request acctivity.
It seems that you have trouble getting an answer to your question in the first 24 hours.
Let us give you a few hints and helpful links.
First, make sure you browsed through our Forum FAQ Beginner’s Guide. It will teach you what should be included in your topic.
You can check out some of our resources directly, see below:
Always search first. It is the best way to quickly find your answer. Check out the icon for that.
Clicking the options button will let you set more specific topic search filters, i.e. only the ones with a solution.
Topic that contains most common solutions with example project files can be found here.
Read our official documentation where you can find a lot of information and instructions about each of our products:
Meet us and our users on our Community Slack and ask your question there.
Hopefully this will let you easily find the solution/information you need. Once you have it, we would be happy if you could share your findings here and mark it as a solution. This will help other users find it in the future.
Thank you for helping us build our UiPath Community!
Hello Nagareetha,
In this video, I use multipart/form-data:
0:20 cURL example
1:35 Send the command from POSTMAN
2:50 Implement the code in C#
4:20 Run the code
4:50 Visual Basic code VB.NET
6:20 New Process on UiPath Studio with Invoke Code
7:20 Imports Libraries in UiPath Studio
8:30 Run the Robot to Upload and Download the file
Blockquote
Dim client As HttpClient = New HttpClient()
client.BaseAddress = New Uri(“YOUR URL”)
client.DefaultRequestHeaders.Accept.Clear()
client.DefaultRequestHeaders.Accept.Add(New MediaTypeWithQualityHeaderValue(“application/vnd.openxmlformats-officedocument.wordprocessingml.document”))
// for BASIC AUTH
Dim byteArray As Byte() = Encoding.ASCII.GetBytes(“username:password”)
client.DefaultRequestHeaders.Authorization = New AuthenticationHeaderValue(“Basic”, Convert.ToBase64String(byteArray))Dim byteArray As Byte() = Encoding.ASCII.GetBytes(“username:password”)
// for OAUTH2
client.DefaultRequestHeaders.Add(“authorization”, “Bearer YOUR TOKEN”)
Dim request As MultipartFormDataContent = New MultipartFormDataContent()
request.Add(New StringContent(“tags”), “Bad”)
request.Add(New StringContent(“displayreferencetext”), “true”)
request.Add(New StringContent(“similaritythreshold”), “0.63”)
request.Add(New StreamContent(File.OpenRead(“C:\8A.docx”)), “file”, (New FileInfo(“C:\8A.docx”).Name))
Dim response As HttpResponseMessage = client.PostAsync(“”, request).Result
Dim strm As Stream = response.Content.ReadAsStreamAsync.Result
Dim doc As Byte()
Dim ms As MemoryStream = New MemoryStream()
strm.CopyTo(ms)
doc = ms.ToArray()
File.WriteAllBytes(“C:\rpa\FORDOWNLOAD\rez.docx”, doc)
Hi,
I have checked and rectified the issue and fixed it, it was with the namespace, I was missing
System.Net.Http
But, on fixing it raise another concern I am keep getting 400 error whereas I had replicated the body inputs as I configured in Postman but over postman its working but in the UiPath I am keep getting the same 400 error, can you help? it’s a form-data POST method
Dim client As HttpClient = New HttpClient()
client.BaseAddress = New Uri("https://xxx.xxx.com/v1/documents")
client.DefaultRequestHeaders.Add("authorization","Bearer XXX")
Dim request As MultipartFormDataContent = New MultipartFormDataContent()
request.Add(New StringContent("docId"),"CW1270984")
request.Add(New StreamContent(File.OpenRead(in_file)), "file", (New FileInfo(in_file).Name))
Dim response As HttpResponseMessage = client.PostAsync("", request).Result
Console.WriteLine(response)
Can you please help me rectify, why It giving this response?