cancel
Showing results for 
Search instead for 
Did you mean: 
Reply
Highlighted
Frequent Visitor

HTTP Post multipart/form-data

Hi,

 

I am trying to post SharePoint files to a 3rd party via their API.  Their API uses multipart/form-data.  After some trial and error, I can POSTcontent, but only text files come out correctly on the destination.  Other files (Excel, Word, jpg, etc.) post, but the data is not readable. What do I need to do to the file content to format it properly?

 

Thanks!

 

http post.png

 

36 REPLIES 36
Highlighted

@davidlist87  Your file content is not base64 encoded. Where you are specifying the file content, use an expression like base64(body('whatever')?['File_Content']) where whatever is the name of the action where you got that file content from dropbox.

 

Write base64() in the expression builder, click between the brackets then switch to the dynamic content tab and find the File Content.

Highlighted

@WillPage thanks for your help but it seams to be throwing an input error.

My expression is: base64(body('When a file is modified')?['triggerBody()'])

Feel like we are really close...

Image 5.jpg

Highlighted

You need to use Get File Content as an additional step. After your trigger, add the Dropbox Get File Content action, and use its output in your HTTP POST.

Highlighted

@WillPage I was able to get the base64 conversion to work but am still getting the same error.

Thanks very much for your help mate👍

Image 7.jpg

 

Highlighted

The two properties of the body should be $content and $content-type. You've omitted the dollar signs.

I took the time to document this here: https://willpagenz.wordpress.com/2019/12/20/using-the-http-action-to-post-multipart-form-data-in-pow...
Highlighted

@WillPage you are a legend! Thank you so much to your contribution on this subject. Not a lot a info around about and you were all over it 👍

Image 10.jpg

Highlighted

Amazing! It works perfectly. So glad you posted solution, I've been trying to work it out for months 😀

Highlighted

Hi did u guys solve this ? i have a similair problem.  Thats my postman setup, need this into power automate. Its demanding a multipart/form-data, and a jpg url 

postman.png

Highlighted

Yes, it is solved and works. You cannot use the Postman code. Check how the solution is written. You need to be extremely careful to keep the json correctly formatted and re-write your field names as needed.

Highlighted

what shall be in the headers ? Content-type : multipart/form-data ? 

Highlighted

Hm getting connection, but image its not uploaded. I know the server demands multipart/form-data and jpeg 

this its my input 

{"uri":"https://login.glaskontroll.se/apitest/filesubmit.php","method":"POST","headers":{"Content-Type":"multipart/form-data"},"body":{"$content-type":"multipart/form-data","$multipart":[{"headers":{"Content-Disposition":"form-data; name=\"Username\""},"body":"test"},{"headers":{"Content-Disposition":"form-data; name=\"Password\""},"body":"pw"},{"headers":{"Content-Disposition":"form-data; name=\"Carregno\""},"body":"LJ0000"},{"headers":{"Content-Disposition":"form-data; name=\"Type\""},"body":"damage"},{"headers":{"Content-Disposition":"form-data; name=\"file\"; filename=\"navn.jpg\""},"body":{"$content-type":"application/jpg","$content":"base64url 
Highlighted

Not sure what is the output of your base64url...but in a previous action try getting file content (save file first to OneDrive for Business) and then put a base64() expression around your file content. Your expression will look like this:

base64(outputs('Get_file_content')?['body'])

 

Highlighted

Made it work, only thing its that i store the images in a collection from power apps, and some of the images its getting a "," before the base64url and causes a conflict 

Highlighted
Impactful Individual
Impactful Individual

You could trim off any leading comma in a compose using a formula like this (warning, phone typing!):

 

If(equals(substring({url},0,1),','),substring({url},1,sub(length({url}),1)),{url})

 

Where {url} is the dynamic content that contains the string. What this does is look at the first character, and if it equals a comma then trim the first character off, else return the whole string.

Highlighted

thanks it worked. One thing i am struggling with its that i think the power apps never executed the flow... The flow works if i test in power automate but when i test in power apps i dont see any response on the web server 

Highlighted

Make sure you have set the button / trigger correctly in PowerApps. See documentation below:

https://docs.microsoft.com/en-us/powerapps/maker/canvas-apps/using-logic-flows

 

If you have made changes in the Flow it may have broken the connection in PowerApps. To fix you remove the connection in PowerApps and then add it again (essentially refresh the connection). 

 

A good habit when doing this update is before reconnecting copy your existing PowerApp connection code somewhere. Once you update you lose any custom codes, variables etc that you wrote.

Highlighted

Found the issue it still inserts "," before the base64 😕

Helpful resources

Announcements
Community Conference

Power Platform Community Conference

Check out the on demand sessions that are available now!

Power Platform ISV Studio

Power Platform ISV Studio

ISV Studio is designed to become the go-to Power Platform destination for ISV’s to monitor & manage published applications.

Top Solution Authors
Top Kudoed Authors
Users online (9,597)