POST jpeg via HTTP Request - corrupted file

I’m trying up POST jpg-files via REST API but doing it from UIPath results in an image-file that can’t be read. The server receives the file but as “mime”: “application/octet-stream”,
If I do the same operation from Postman the file is perfectly posted as “mime”: “image/jpeg”.
I can not understand what is wrong. I’m told to use form data but when adding that to the headers (Content-Type, Direction: In, Type: String, Value: “multipart/form-data”) I end up with an error message saying:
400 {“error”:“bad_request”,“error_description”:“No uploaded file found. Please upload the file using the multipart/form-data specification”}

Currently I use no headers and no parameters. Only Body format set to multipart/form-data

I’ve read many threads with similar issues but nobody seems to have sorted this out. Anyone succeeded? Since it works so well from Postman I’m starting to think that HTTP Request may be buggy.

Hi @HenrikX

Would you mind sharing a sample, fresh project that reproduces this issue? You can remove the sensitive data, of course.

It would help if you had already tested the latest Studio 20.10 and the latest UiPath.Web.Activities package.

1 Like

Yes, absolutely. Here is my current example. As you can see the receiving server sees this as “mime”: “application/octet-stream” instead of “mime”: “image/jpeg”, that it should be.


Using Postman or cURL does the job perfectly with no problem what soever. With UIPath I have struggled numerous hours without success.
Searching the forum for “post form-data” or “HTTP Activity POST Attachment” will give many threads of people loosing their hair over this issue.
I’m using 2020.4.2.

Hi @HenrikX!

I see that your BodyFormat value is “form-data”, which is not a valid MIME type. Don’t worry about it, as the HTTP Request activity automatically uses the valid “multipart/form-data” MIME type if you add an attachment, as you did.

I’m not sure what the logs that you’ve attached represent. They don’t seem to be request headers and I’m not sure what the expected behavior is in your case. I think that this has more to do with your web server than with the HTTP Request activity configuration.

Here’s a sample of how I’m using the same activity with good results.

I have a small NodeJS web server listening for uploads, here’s the code for it const express = require('express')const fileUpload = require('express-fileuplo - Pastebin.com

When I run the process, the web server logs this information:

{
  accept: '*/*',
  'user-agent': 'RestSharp/106.6.10.0',
  'content-type': 'multipart/form-data; boundary=-----------------------------28947758029299',
  host: 'localhost:3000',
  'content-length': '490824',
  'accept-encoding': 'gzip, deflate',
  connection: 'Keep-Alive'
}
File saved to 1599726890317.jpg

and the file gets uploaded in the designated folder and can be easily opened with any photo viewer app.

My best guess is that you’re somehow trying to process the image on the web server and you’re not getting the results you want, but that doesn’t mean that the HTTP request (i.e. the actual request, not the activity) is not well formatted.

Can you please explain your second screenshot a bit better? How are those properties generated? Can you also paste the raw incoming request headers?

1 Like

Hi! Thank you for the response.
The code I pasted is the response from the server showing that it does not understand the mime-type. As this is working flawlessly using cURL or Postman I do not see any reason to suspect any error on the server side.
I’m afraid I don’t have the skills to set up a server to listen to incoming request. The server I’m trying to upload to is a large e-commerce platform.
Looking at your screen shots I can’t spot anything that differs besides “form-data” but as you say that shouldn’t make any difference. No sure how I could present more details as the HTTP Request activity basically only contains the Endpoint, Attachment and credentials. Not much to do wrong I suppose.

I understand there is a difference between Postman and HTTP Request, but it seems like the activity is doing what it should, so I can’t figure out what your server does that makes it disregard the fact that the activity is sending sending an image. I can assure you that all of the image’s bytes reach the server.

I will try to investigate further what the difference might be. If you come across some new information, please post it here.

Could you try a site like https://webhook.site/ and send the same request to the same URL it gives you, one from Postman and once from Studio?

This would allow you to compare the two in a quite visual way (by switching between the two requests). This might give you some clues.

Hi @HenrikX

Could you let us know if you managed to debug this issue further? :slight_smile:

Hi All

I have some doubts about the use of the Http Activitie, I could not find any conversation talking how to do the http request with attached files like this, so please @loginerror could you help how can I do to use the UiPath activitie with the next example, I think it colud be very useful for the communitie, I want to use de API of an OCR IA Model but it is working in Postman, but I cant do it work in UiPath, see information below:

#1 Process file using multipart/form-data upload

Submit a request to process a multipart/form-data file upload.

HTTP Request

POST https://ENVIRONMENT_URL/api/v7/partner/documents/

Query Parameters
Field Type Required Description
file_name String Y File name (eg. starbucks.jpg)
file File Y File (pdf, jpg, .jpeg, .png)
categories List N List of categories, if you would like to use your own list and it’s different from the Default one [“Meals & Entertainment”, “Travel”, …]
max_pages_to_process Int N When sending a long document to Veryfi for processing, this paremeter controls how many pages of the document will be read and processed, starting from page 1.
boost_mode Int N Flag that tells Veryfi whether boost mode should be enabled. When set to 1, Veryfi will skip data enrichment steps, but will process the document faster. Default value for this flag is 0.
external_id String N Optional custom document identifier. Use this if you would like to assign your own ID to documents

CURL:

curl -H “Content-Type: multipart/form-data” -H “Accept: application/json” -H “CLIENT-ID: CLIENT_ID” -H “AUTHORIZATION: apikey USERNAME:API_KEY” -X POST -F ‘file=@/Users/admin/tmp/panera_receipt.pdf’ -F ‘file_name=panera_receipt.pdf’ https://ENVIRONMENT_URL/api/v7/partner/documents/

Get a Document

Retrieve a previously processed document.

HTTP Request

GET https://ENVIRONMENT_URL/api/v7/partner/documents/DOCUMENT_ID/

curl -H “Content-Type: application/json” \ -H “Accept: application/json” \ -H “CLIENT-ID: CLIENT_ID” \ -H “AUTHORIZATION: apikey USERNAME:API_KEY” \ -X GET https://ENVIRONMENT_URL/api/v7/partner/documents/DOCUMENT_ID/

Thanks for your help!

Hi @Eloy_Jimenez_Vidal

Have you already tried the method explained above?

Remove your credentials and try sending both requests - from Postman and from Studio - to the same random URL of webhook.site.

Then, please compare the two received requests to see if there are any differences. Feel free to provide screenshots as well, together with the setup you have in Studio properties panel for your HTTP Request activity.

Hello Henrik,
In this video, you can see how I upload files to multiple systems (Maybe this will help you with your issue):
Uipath upload files in Jira (REST API) (HTTP REQUEST) | Jira REST API upload file - YouTube
ServiceNow Upload files without Administrator Rights with UiPath Robots | RPA files | REST API file - YouTube
Thanks,
Cristian Negulescu