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

 

51 REPLIES 51

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

Anonymous
Not applicable

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.

Anonymous
Not applicable

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

Anonymous
Not applicable

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

 

Anonymous
Not applicable

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.

Anonymous
Not applicable

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.

Anonymous
Not applicable

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

Community Roundup: A Look Back at Our Last 10 Tuesday Tips

As we continue to grow and learn together, it's important to reflect on the valuable insights we've shared. For today's #TuesdayTip, we're excited to take a moment to look back at the last 10 tips we've shared in case you missed any or want to revisit them. Thanks for your incredible support for this series--we're so glad it was able to help so many of you navigate your community experience!   Getting Started in the Community An overview of everything you need to know about navigating the community on one page!  Community Links: ○ Power Apps ○ Power Automate  ○ Power Pages  ○ Copilot Studio    Community Ranks and YOU Have you ever wondered how your fellow community members ascend the ranks within our community? We explain everything about ranks and how to achieve points so you can climb up in the rankings! Community Links: ○ Power Apps ○ Power Automate  ○ Power Pages  ○ Copilot Studio    Powering Up Your Community Profile Your Community User Profile is how the Community knows you--so it's essential that it works the way you need it to! From changing your username to updating contact information, this Knowledge Base Article is your best resource for powering up your profile. Community Links: ○ Power Apps ○ Power Automate  ○ Power Pages  ○ Copilot Studio    Community Blogs--A Great Place to Start There's so much you'll discover in the Community Blogs, and we hope you'll check them out today!  Community Links: ○ Power Apps ○ Power Automate  ○ Power Pages  ○ Copilot Studio    Unlocking Community Achievements and Earning Badges Across the Communities, you'll see badges on users profile that recognize and reward their engagement and contributions. Check out some details on Community badges--and find out more in the detailed link at the end of the article! Community Links: ○ Power Apps  ○ Power Automate  ○ Power Pages  ○ Copilot Studio    Blogging in the Community Interested in blogging? Everything you need to know on writing blogs in our four communities! Get started blogging across the Power Platform communities today! Community Links: ○ Power Apps  ○ Power Automate  ○ Power Pages  ○ Copilot Studio   Subscriptions & Notifications We don't want you to miss a thing in the community! Read all about how to subscribe to sections of our forums and how to setup your notifications! Community Links: ○ Power Apps  ○ Power Automate  ○ Power Pages  ○ Copilot Studio   Getting Started with Private Messages & Macros Do you want to enhance your communication in the Community and streamline your interactions? One of the best ways to do this is to ensure you are using Private Messaging--and the ever-handy macros that are available to you as a Community member! Community Links: ○ Power Apps  ○ Power Automate  ○ Power Pages  ○ Copilot Studio   Community User Groups Learn everything about being part of, starting, or leading a User Group in the Power Platform Community. Community Links: ○ Power Apps  ○ Power Automate  ○ Power Pages  ○ Copilot Studio   Update Your Community Profile Today! Keep your community profile up to date which is essential for staying connected and engaged with the community. Community Links: ○ Power Apps  ○ Power Automate  ○ Power Pages  ○ Copilot Studio   Thank you for being an integral part of our journey.   Here's to many more Tuesday Tips as we pave the way for a brighter, more connected future! As always, watch the News & Announcements for the next set of tips, coming soon!    

Calling all User Group Leaders and Super Users! Mark Your Calendars for the next Community Ambassador Call on May 9th!

This month's Community Ambassador call is on May 9th at 9a & 3p PDT. Please keep an eye out in your private messages and Teams channels for your invitation. There are lots of exciting updates coming to the Community, and we have some exclusive opportunities to share with you! As always, we'll also review regular updates for User Groups, Super Users, and share general information about what's going on in the Community.     Be sure to register & we hope to see all of you there!

April 2024 Community Newsletter

We're pleased to share the April Community Newsletter, where we highlight the latest news, product releases, upcoming events, and the amazing work of our outstanding Community members.   If you're new to the Community, please make sure to follow the latest News & Announcements and check out the Community on LinkedIn as well! It's the best way to stay up-to-date with all the news from across Microsoft Power Platform and beyond.    COMMUNITY HIGHLIGHTS   Check out the most active community members of the last month! These hardworking members are posting regularly, answering questions, kudos, and providing top solutions in their communities. We are so thankful for each of you--keep up the great work! If you hope to see your name here next month, follow these awesome community members to see what they do!   Power AppsPower AutomateCopilot StudioPower PagesWarrenBelzDeenujialexander2523ragavanrajanLaurensMManishSolankiMattJimisonLucas001AmikcapuanodanilostephenrobertOliverRodriguestimlAndrewJManikandanSFubarmmbr1606VishnuReddy1997theMacResolutionsVishalJhaveriVictorIvanidzejsrandhawahagrua33ikExpiscornovusFGuerrero1PowerAddictgulshankhuranaANBExpiscornovusprathyooSpongYeNived_Nambiardeeksha15795apangelesGochixgrantjenkinsvasu24Mfon   LATEST NEWS   Business Applications Launch Event - On Demand In case you missed the Business Applications Launch Event, you can now catch up on all the announcements and watch the entire event on-demand inside Charles Lamanna's latest cloud blog.   This is your one stop shop for all the latest Copilot features across Power Platform and #Dynamics365, including first-hand looks at how companies such as Lenovo, Sonepar, Ford Motor Company, Omnicom and more are using these new capabilities in transformative ways. Click the image below to watch today!   Power Platform Community Conference 2024 is here! It's time to look forward to the next installment of the Power Platform Community Conference, which takes place this year on 18-20th September 2024 at the MGM Grand in Las Vegas!   Come and be inspired by Microsoft senior thought leaders and the engineers behind the #PowerPlatform, with Charles Lamanna, Sangya Singh, Ryan Cunningham, Kim Manis, Nirav Shah, Omar Aftab and Leon Welicki already confirmed to speak. You'll also be able to learn from industry experts and Microsoft MVPs who are dedicated to bridging the gap between humanity and technology. These include the likes of Lisa Crosbie, Victor Dantas, Kristine Kolodziejski, David Yack, Daniel Christian, Miguel Félix, and Mats Necker, with many more to be announced over the coming weeks.   Click here to watch our brand-new sizzle reel for #PPCC24 or click the image below to find out more about registration. See you in Vegas!       Power Up Program Announces New Video-Based Learning Hear from Principal Program Manager, Dimpi Gandhi, to discover the latest enhancements to the Microsoft #PowerUpProgram. These include a new accelerated video-based curriculum crafted with the expertise of Microsoft MVPs, Rory Neary and Charlie Phipps-Bennett. If you’d like to hear what’s coming next, click the image below to find out more!   UPCOMING EVENTS Microsoft Build - Seattle and Online - 21-23rd May 2024 Taking place on 21-23rd May 2024 both online and in Seattle, this is the perfect event to learn more about low code development, creating copilots, cloud platforms, and so much more to help you unleash the power of AI.   There's a serious wealth of talent speaking across the three days, including the likes of Satya Nadella, Amanda K. Silver, Scott Guthrie, Sarah Bird, Charles Lamanna, Miti J., Kevin Scott, Asha Sharma, Rajesh Jha, Arun Ulag, Clay Wesener, and many more.   And don't worry if you can't make it to Seattle, the event will be online and totally free to join. Click the image below to register for #MSBuild today!   European Collab Summit - Germany - 14-16th May 2024 The clock is counting down to the amazing European Collaboration Summit, which takes place in Germany May 14-16, 2024. #CollabSummit2024 is designed to provide cutting-edge insights and best practices into Power Platform, Microsoft 365, Teams, Viva, and so much more. There's a whole host of experts speakers across the three-day event, including the likes of Vesa Juvonen, Laurie Pottmeyer, Dan Holme, Mark Kashman, Dona Sarkar, Gavin Barron, Emily Mancini, Martina Grom, Ahmad Najjar, Liz Sundet, Nikki Chapple, Sara Fennah, Seb Matthews, Tobias Martin, Zoe Wilson, Fabian Williams, and many more.   Click the image below to find out more about #ECS2024 and register today!     Microsoft 365 & Power Platform Conference - Seattle - 3-7th June If you're looking to turbo boost your Power Platform skills this year, why not take a look at everything TechCon365 has to offer at the Seattle Convention Center on June 3-7, 2024.   This amazing 3-day conference (with 2 optional days of workshops) offers over 130 sessions across multiple tracks, alongside 25 workshops presented by Power Platform, Microsoft 365, Microsoft Teams, Viva, Azure, Copilot and AI experts. There's a great array of speakers, including the likes of Nirav Shah, Naomi Moneypenny, Jason Himmelstein, Heather Cook, Karuana Gatimu, Mark Kashman, Michelle Gilbert, Taiki Y., Kristi K., Nate Chamberlain, Julie Koesmarno, Daniel Glenn, Sarah Haase, Marc Windle, Amit Vasu, Joanne C Klein, Agnes Molnar, and many more.   Click the image below for more #Techcon365 intel and register today!     For more events, click the image below to visit the Microsoft Community Days website.      

Tuesday Tip | Update Your Community Profile Today!

It's time for another TUESDAY TIPS, your weekly connection with the most insightful tips and tricks that empower both newcomers and veterans in the Power Platform Community! Every Tuesday, we bring you a curated selection of the finest advice, distilled from the resources and tools in the Community. Whether you’re a seasoned member or just getting started, Tuesday Tips are the perfect compass guiding you across the dynamic landscape of the Power Platform Community.   We're excited to announce that updating your community profile has never been easier! Keeping your profile up to date is essential for staying connected and engaged with the community.   Check out the following Support Articles with these topics: Accessing Your Community ProfileRetrieving Your Profile URLUpdating Your Community Profile Time ZoneChanging Your Community Profile Picture (Avatar)Setting Your Date Display Preferences Click on your community link for more information: Power Apps, Power Automate, Power Pages, Copilot Studio   Thank you for being an active part of our community. Your contributions make a difference! Best Regards, The Community Management Team

Hear what's next for the Power Up Program

Hear from Principal Program Manager, Dimpi Gandhi, to discover the latest enhancements to the Microsoft #PowerUpProgram, including a new accelerated video-based curriculum crafted with the expertise of Microsoft MVPs, Rory Neary and Charlie Phipps-Bennett. If you’d like to hear what’s coming next, click the link below to sign up today! https://aka.ms/PowerUp  

Super User of the Month | Ahmed Salih

We're thrilled to announce that Ahmed Salih is our Super User of the Month for April 2024. Ahmed has been one of our most active Super Users this year--in fact, he kicked off the year in our Community with this great video reminder of why being a Super User has been so important to him!   Ahmed is the Senior Power Platform Architect at Saint Jude's Children's Research Hospital in Memphis. He's been a Super User for two seasons and is also a Microsoft MVP! He's celebrating his 3rd year being active in the Community--and he's received more than 500 kudos while authoring nearly 300 solutions. Ahmed's contributions to the Super User in Training program has been invaluable, with his most recent session with SUIT highlighting an incredible amount of best practices and tips that have helped him achieve his success.   Ahmed's infectious enthusiasm and boundless energy are a key reason why so many Community members appreciate how he brings his personality--and expertise--to every interaction. With all the solutions he provides, his willingness to help the Community learn more about Power Platform, and his sheer joy in life, we are pleased to celebrate Ahmed and all his contributions! You can find him in the Community and on LinkedIn. Congratulations, Ahmed--thank you for being a SUPER user!

Users online (4,837)