Finally, add the following code (make changes as necessary):
Dim client As RestClient = New RestClient("https://example.com/api/v2/uploads.json?filename=test.png")
client.Timeout = 10000
Dim request As RestRequest= New RestRequest(Method.POST)
request.AddHeader("Content-Type", "image/png")
request.AddParameter("image/png", File.ReadAllBytes("C:\Users\gustavo.cervelin\Downloads\test.png"), ParameterType.RequestBody)
Dim response As IRestResponse = client.Execute(request)
Console.WriteLine(response.Content)
IMPORTANT NOTES:
At line four, set the content type according your file extension;
The same for line five
That’s it!
If you need help to work with the response, let me know
Hi @barryrodick ,
I needed to do something like that.
I send an image to a web service that decrypts what is written and gives me back a string (I use this to break captcha).
Using the HTTP Request activity (UiPath.Web.Activities) in the ** Attachments ** property, I configure the file to be sent.
I imported restsharp, I thought it would be an option here
Dim client As RestClient = New RestClient("------/api/1/files/content?parentfolderid=973119")
client.Timeout = 10000
Dim request As RestRequest= New RestRequest(Method.POST)
request.AddHeader("Authorization","Bearer XXXXXXXXXXX")
request.AddHeader("Content-Type", "multipart/form-data;")
request.AddParameter("text/plain", File.ReadAllBytes("<U+202A>C:\Users\rodickb\Desktop\HiQTest.txt"), ParameterType.RequestBody)
request.AddParameter("filename","UploadTest1", ParameterType.RequestBody)
Dim response As IRestResponse = client.Execute(request)
Console.WriteLine(response.Content
Ended your code above, but only given this error
Invoke code: Exception has been thrown by the target of an invocation.
Dim client As RestClient = New RestClient(“https://------------------/api/1/files/content?parentfolderid=973119”)
client.Timeout = -1
Dim request As RestRequest = New RestRequest(Method.POST)
request.AddHeader(“Authorization”, “Bearer -----------------”)
request.AddParameter(“filename”, “NameOfFile”)
request.AddFile(“file”, “C:/Users/rodickb/Desktop/HiQTest.txt”)
Dim response As IRestResponse = client.Execute(request)
Console.WriteLine(response.Content)