cancel
Showing results for 
Search instead for 
Did you mean: 
Reply
JonathanM
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

 

50 REPLIES 50

@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.

@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

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.

@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

 

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...

@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

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

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

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.

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

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 

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'])

 

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 

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.

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 

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.

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

@WillPage 

@Anonymous 

 

Awesome work you guys have done here! 👍

cindyc
Frequent Visitor

Guys, thanks so much for all the great work!  It helped me immensely! I wanted to share what I was trying to accomplish and some of the things that you guys showed that got it working, just in case my scenario is similar to someone elses;

 

In MS FLOW, The built-in HTTP action is a "PREMIUM" action. I'm trying not to have the company Im helping spend anymore than they already are on MS TEAMS etc, so I can't/won't use any premium actions.

 

What I'm trying to do is come up with a free way to make a REST API call to my computer (that has a public hostname setup on one of my machines) so that when I send a PDF file over the API, I can have Flask/Python convert it into a text file, and send parsed out fields back to MS FLOW in json format.

 

It looks like Custom Connectors is the way to go.  But I ran into some problems.  Everything worked perfectly on Postman, the multipart/form-data was picked up from the request inside the request.files dict in flask, and I was able to (test save to make sure it was not corrupt) work on the file PDF no sweat. But when I tried to export the Postman collection in v1 export, it would not work.  I tried exporting the Postman v2 file and converting it to Swagger/OpenApi 2.0 json file, and while the conversion worked fine, getting the multipart/form-data piece to put the file inside request.files did not work, no matter what I tried.  But then I found this thread and things started to come together. After alot of fruitless testing from the Custom Connector Swagger Editor (it kept putting an @ in front of the filename for some reason, but I copied the CURL command and ran it from cmd, still to no avail), and then trying "Import from sample" in the Custom Connector Definition screen, nothing seemed to work, although a few times the filename did appear in requests.form dict in flask, but the data was not there. I tried putting the "$content-type": "multipart/form-data" string inside the header, and that didn't work either.  I did Use the MS FLOW HTTP action for a bit though, cuz I think you get a 30 day trial. Here is what I put in the HTTP action body section, with no header info, just to see if it would work;

 

cindyc_0-1612573646318.png

 

It worked just like the guys here said it would, multipart/form-data worked just like Postman did, and Flask/Python picked the file up in request.files and I was able to save the pdf file no prob. What worked for me to make sure the pdf file was not corrupted once it got to Flask/Python was to use;

 

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

 

I tried a few iterations like base64(outputs('Get_file_content')) <-- no ['body'], but the above was the one that worked.

 

But my custom connector was still having problems. Here is what finally worked in the "Import from sample" section, just like the guys here said it would;

 

cindyc_7-1612576459856.png

 

 

I just blurred out the filename above in the pic a little bit, but if you do it this way uploading a file via a MS FLOW Custom Connector will work.  Now here is one thing that stumped me; the Custom Connector "Test" screen. 

 

cindyc_2-1612574665070.png

 

I tested via this thing many, many times, and although the REST API call was made, the multipart/form-data was not properly formatted in the request object, meaning the pdf file was never in either request.files or request.form, or in the json object inside the request. But I decided to plug this Custom Connector inside the Flow I was working on, just to see if maybe it would be different, and possibly be properly formatted in the request object. And sure enough it was! Here is a look at the Flask/Python debugger with the pdf file inside request.files;

 

cindyc_9-1612577035392.png

 

What this shows is that the pdf 'file' is inside the requests.files dict and the multipart/form-data is properly formatted inside the REST API function. 

 

One other thing that got me right before it started working was how I was putting in the variables in the Connector once I put it into my Flow. In the Content-Disposition field I entered the information just like I did when I built the Custom Connector using "form-data; name=\"file\"; filename=\"20210129172849290.pdf\"".

But when it gets to the API, it will add a bunch of extra uneeded characters.  I decided not to use the text editor fields to put the data inside the Connector, I just use the fields/text boxes provided by the Custom Connector which works fine. So I removed the slashes and double quotes, and now here is what the Custom Connector looks like inside my flow with everything working (just blurred the filename a little);

 

cindyc_8-1612576638749.png

 

 

Thank you so much for all the help, I was pulling my hair out for a long while, could not have done it without you!,

Thanks,

EC

 

 

TT_TX
New Member

First I want to say thanks to everyone on this post as it helped me get to this point.  I have a similar use case in needing to copy files from OneDrive/DropBox etc. to Procore's Document Management Tool via their file upload API which requires a multipart/form-data format.  I ran into similar roadblocks as mentioned previously in this post but was able to configure a Custom Connector to accomplish this by taking the following steps:  

 

Note that Procore's API's require OAuth 2.0 and hence part of my motivation to use a Custom Connector as I was able to get the authentication piece working with other Procore API calls.         

 

Steps Taken:

1.  Successfully tested the API using Postman - Body - form-data

Postman Procore File Upload.png

 

2. Exported the Postman Collection in v2.1 format

Postman Collection Export.png

3. Even though the Power Automate Custom Connector import shows that it supports Postman v1.0, v2.0 and v2.1 it only seems to support v1.0 which I confirmed with MS Support.  The latest version of Postman does not support exporting in v1.0 so per MS Support's suggestion, I used APIMatic to convert the file.  When I attempted to convert it to Postman v1.0 it seemed to drop the "multipart/form-data" configuration.  I don't know if this is because v1.0 didn't support it or if conversion tool has an issue but regardless I decided to convert it to OpenAPI/Swagger v2.0 (JSON) instead with the idea of pasting it directly into the Swagger Editor.  

APIMatic .png

   

4.  The converted File for some reason set the following even though the Postman export was correct: 

  • "consumes["application/x-www-form-urlencoded"],
  • {name: 'file[data]', in: formData, required: true, type: string, description: ''}

5.  Manually replaced the following

  • "consumes": ["multipart/form-data"],
  • {name: 'file[data]', in: formData, required: true, type: file, description: ''}

6.  Pasted converted/modified file directly into the Swagger Editor.  Note that when creating (saving) the Custom Connector and re-opening the Swagger Editor, what I pasted was reformatted but code remained in-tact.  

TT_TX_0-1629664095662.png

PA Customer Connector - Swagger 2_0.jpg

7.   Next I attempted to use Swagger to test the call but received "TypeError:  Failed to Fetch".  Any suggestion here would be appreciated.  

Swagger Test.jpg

TT_TX_1-1629664179772.png

 

8.  Used the Connector in a Flow.  Note that I had to enter the File Content under "body" vs.  File[data] which doesn't make sense to me.  I didn't expect to see "body" as a field... any suggestions here would also be appreciated.   

 
 

Custom Connector In Flow.jpg

9.  Validated files uploaded successfully

Procore Success.jpg

 Next step will be to stress test this by uploading 500+ files via looping through a list but thought I would share to this point.    

Helpful resources

Announcements

Power Platform Connections Ep 15 | L. Baybutt | Thursday, 1 June 2023

Episode Fifteen of Power Platform Connections sees David Warner and Hugo Bernier talk to Microsoft MVP Lewis Baybutt aka Low Code Lewis, alongside the latest news and community blogs.   Use the hashtag #PowerPlatformConnects on social media for a chance to have your work featured on the show.        Action requested: Feel free to provide feedback on how we can make our community more inclusive and diverse.  This episode premiers live on our YouTube at 12pm PST on Thursday 1st June 2023.  Video series available at Power Platform Community YouTube channel.    Upcoming events:  European Power Platform conference – Jun. 20-22nd - Dublin Microsoft Power Platform Conference – Oct. 3-5th - Las Vegas  Join our Communities:  Power Apps Community Power Automate Community Power Virtual Agents Community Power Pages Community  If you’d like to hear from a specific community member in an upcoming recording and/or have specific questions for the Power Platform Connections team, please let us know. We will do our best to address all your requests or questions.  Action requested: Feel free to provide feedback on how we can make our community more inclusive and diverse.  This episode premiers live on our YouTube at 12pm PST on Thursday 1st June 2023.  Video series available at Power Platform Community YouTube channel.    Upcoming events:  European Power Platform conference – Jun. 20-22nd - Dublin Microsoft Power Platform Conference – Oct. 3-5th - Las Vegas  Join our Communities:  Power Apps Community Power Automate Community Power Virtual Agents Community Power Pages Community  If you’d like to hear from a specific community member in an upcoming recording and/or have specific questions for the Power Platform Connections team, please let us know. We will do our best to address all your requests or questions. 

May 2023 Community Newsletter and Upcoming Events

Welcome to our May 2023 Community Newsletter, where we'll be highlighting the latest news, releases, upcoming events, and the great work of our members inside the Biz Apps communities. If you're new to this LinkedIn group, be sure to subscribe here in the News & Announcements to stay up to date with the latest news from our ever-growing membership network who "changed the way they thought about code".         LATEST NEWS "Mondays at Microsoft" LIVE on LinkedIn - 8am PST - Monday 15th May  - Grab your Monday morning coffee and come join Principal Program Managers Heather Cook and Karuana Gatimu for the premiere episode of "Mondays at Microsoft"! This show will kick off the launch of the new Microsoft Community LinkedIn channel and cover a whole host of hot topics from across the #PowerPlatform, #ModernWork, #Dynamics365, #AI, and everything in-between. Just click the image below to register and come join the team LIVE on Monday 15th May 2023 at 8am PST. Hope to see you there!     Executive Keynote | Microsoft Customer Success Day CVP for Business Applications & Platform, Charles Lamanna, shares the latest #BusinessApplications product enhancements and updates to help customers achieve their business outcomes.         S01E13 Power Platform Connections - 12pm PST - Thursday 11th May Episode Thirteen of Power Platform Connections sees Hugo Bernier take a deep dive into the mind of co-host David Warner II, alongside the reviewing the great work of Dennis Goedegebuure, Keith Atherton, Michael Megel, Cat Schneider, and more. Click below to subscribe and get notified, with David and Hugo LIVE in the YouTube chat from 12pm PST. And use the hashtag #PowerPlatformConnects on social media for a chance to have your work featured on the show.         UPCOMING EVENTS   European Power Platform Conference - early bird ticket sale ends! The European Power Platform Conference early bird ticket sale ends on Friday 12th May 2023! #EPPC23 brings together the Microsoft Power Platform Communities for three days of unrivaled days in-person learning, connections and inspiration, featuring three inspirational keynotes, six expert full-day tutorials, and over eighty-five specialist sessions, with guest speakers including April Dunnam, Dona Sarkar, Ilya Fainberg, Janet Robb, Daniel Laskewitz, Rui Santos, Jens Christian Schrøder, Marco Rocca, and many more. Deep dive into the latest product advancements as you hear from some of the brightest minds in the #PowerApps space. Click here to book your ticket today and save!      DynamicMinds Conference - Slovenia - 22-24th May 2023 It's not long now until the DynamicsMinds Conference, which takes place in Slovenia on 22nd - 24th May, 2023 - where brilliant minds meet, mingle & share! This great Power Platform and Dynamics 365 Conference features a whole host of amazing speakers, including the likes of Georg Glantschnig, Dona Sarkar, Tommy Skaue, Monique Hayward, Aleksandar Totovic, Rachel Profitt, Aurélien CLERE, Ana Inés Urrutia de Souza, Luca Pellegrini, Bostjan Golob, Shannon Mullins, Elena Baeva, Ivan Ficko, Guro Faller, Vivian Voss, Andrew Bibby, Tricia Sinclair, Roger Gilchrist, Sara Lagerquist, Steve Mordue, and many more. Click here: DynamicsMinds Conference for more info on what is sure an amazing community conference covering all aspects of Power Platform and beyond.    Days of Knowledge Conference in Denmark - 1-2nd June 2023 Check out 'Days of Knowledge', a Directions 4 Partners conference on 1st-2nd June in Odense, Denmark, which focuses on educating employees, sharing knowledge and upgrading Business Central professionals. This fantastic two-day conference offers a combination of training sessions and workshops - all with Business Central and related products as the main topic. There's a great list of industry experts sharing their knowledge, including Iona V., Bert Verbeek, Liza Juhlin, Douglas Romão, Carolina Edvinsson, Kim Dalsgaard Christensen, Inga Sartauskaite, Peik Bech-Andersen, Shannon Mullins, James Crowter, Mona Borksted Nielsen, Renato Fajdiga, Vivian Voss, Sven Noomen, Paulien Buskens, Andri Már Helgason, Kayleen Hannigan, Freddy Kristiansen, Signe Agerbo, Luc van Vugt, and many more. If you want to meet industry experts, gain an advantage in the SMB-market, and acquire new knowledge about Microsoft Dynamics Business Central, click here Days of Knowledge Conference in Denmark to buy your ticket today!   COMMUNITY HIGHLIGHTS Check out our top Super and Community Users reaching new levels! These hardworking members are posting, answering questions, kudos, and providing top solutions in their communities.   Power Apps:  Super Users: @WarrenBelz, @LaurensM  @BCBuizer  Community Users:  @Amik@ @mmollet, @Cr1t    Power Automate:  Super Users: @Expiscornovus , @grantjenkins, @abm  Community Users: @Nived_Nambiar, @ManishSolanki    Power Virtual Agents:  Super Users: @Pstork1, @Expiscornovus  Community Users: @JoseA, @fernandosilva, @angerfire1213    Power Pages: Super Users: @ragavanrajan  Community Users: @Fubar, @Madhankumar_L,@gospa  LATEST COMMUNITY BLOG ARTICLES  Power Apps Community Blog  Power Automate Community Blog  Power Virtual Agents Community Blog  Power Pages Community Blog  Check out 'Using the Community' for more helpful tips and information:  Power Apps , Power Automate, Power Virtual Agents, Power Pages 

Announcing | Super Users - 2023 Season 1

Super Users – 2023 Season 1    We are excited to kick off the Power Users Super User Program for 2023 - Season 1.  The Power Platform Super Users have done an amazing job in keeping the Power Platform communities helpful, accurate and responsive. We would like to send these amazing folks a big THANK YOU for their efforts.      Super User Season 1 | Contributions July 1, 2022 – December 31, 2022  Super User Season 2 | Contributions January 1, 2023 – June 30, 2023    Curious what a Super User is? Super Users are especially active community members who are eager to help others with their community questions. There are 2 Super User seasons in a year, and we monitor the community for new potential Super Users at the end of each season. Super Users are recognized in the community with both a rank name and icon next to their username, and a seasonal badge on their profile.  Power Apps  Power Automate  Power Virtual Agents  Power Pages  Pstork1*  Pstork1*  Pstork1*  OliverRodrigues  BCBuizer  Expiscornovus*  Expiscornovus*  ragavanrajan  AhmedSalih  grantjenkins  renatoromao    Mira_Ghaly*  Mira_Ghaly*      Sundeep_Malik*  Sundeep_Malik*      SudeepGhatakNZ*  SudeepGhatakNZ*      StretchFredrik*  StretchFredrik*      365-Assist*  365-Assist*      cha_cha  ekarim2020      timl  Hardesh15      iAm_ManCat  annajhaveri      SebS  Rhiassuring      LaurensM  abm      TheRobRush  Ankesh_49      WiZey  lbendlin      Nogueira1306  Kaif_Siddique      victorcp  RobElliott      dpoggemann  srduval      SBax  CFernandes      Roverandom  schwibach      Akser  CraigStewart      PowerRanger  MichaelAnnis      subsguts  David_MA      EricRegnier  edgonzales      zmansuri  GeorgiosG      ChrisPiasecki  ryule      AmDev  fchopo      phipps0218  tom_riha      theapurva  takolota     Akash17  momlo     BCLS776  Shuvam-rpa     rampprakash  ScottShearer     Rusk  ChristianAbata     cchannon  Koen5     a33ik  Heartholme     AaronKnox  okeks      Matren  David_MA     Alex_10        Jeff_Thorpe        poweractivate        Ramole        DianaBirkelbach        DavidZoon        AJ_Z        PriyankaGeethik        BrianS        StalinPonnusamy        HamidBee        CNT        Anonymous_Hippo        Anchov        KeithAtherton        alaabitar        Tolu_Victor        KRider        sperry1625        IPC_ahaas      zuurg    rubin_boer   cwebb365   Dorrinda   G1124   Gabibalaban   Manan-Malhotra   jcfDaniel   WarrenBelz   Waegemma   drrickryp   GuidoPreite   metsshan    If an * is at the end of a user's name this means they are a Multi Super User, in more than one community. Please note this is not the final list, as we are pending a few acceptances.  Once they are received the list will be updated. 

Check out the new Power Platform Communities Front Door Experience!

We are excited to share the ‘Power Platform Communities Front Door’ experience with you!   Front Door brings together content from all the Power Platform communities into a single place for our community members, customers and low-code, no-code enthusiasts to learn, share and engage with peers, advocates, community program managers and our product team members. There are a host of features and new capabilities now available on Power Platform Communities Front Door to make content more discoverable for all power product community users which includes ForumsUser GroupsEventsCommunity highlightsCommunity by numbersLinks to all communities Users can see top discussions from across all the Power Platform communities and easily navigate to the latest or trending posts for further interaction. Additionally, they can filter to individual products as well.   Users can filter and browse the user group events from all power platform products with feature parity to existing community user group experience and added filtering capabilities.     Users can now explore user groups on the Power Platform Front Door landing page with capability to view all products in Power Platform.      Explore Power Platform Communities Front Door today. Visit Power Platform Community Front door to easily navigate to the different product communities, view a roll up of user groups, events and forums.

Microsoft Power Platform Conference | Registration Open | Oct. 3-5 2023

We are so excited to see you for the Microsoft Power Platform Conference in Las Vegas October 3-5 2023! But first, let's take a look back at some fun moments and the best community in tech from MPPC 2022 in Orlando, Florida.   Featuring guest speakers such as Charles Lamanna, Heather Cook, Julie Strauss, Nirav Shah, Ryan Cunningham, Sangya Singh, Stephen Siciliano, Hugo Bernier and many more.   Register today: https://www.powerplatformconf.com/   

Users online (3,130)