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

Exclusive LIVE Community Event: Power Apps Copilot Coffee Chat with Copilot Studio Product Team

It's time for the SECOND Power Apps Copilot Coffee Chat featuring the Copilot Studio product team, which will be held LIVE on April 3, 2024 at 9:30 AM Pacific Daylight Time (PDT).     This is an incredible opportunity to connect with members of the Copilot Studio product team and ask them anything about Copilot Studio. We'll share our special guests with you shortly--but we want to encourage to mark your calendars now because you will not want to miss the conversation.   This live event will give you the unique opportunity to learn more about Copilot Studio plans, where we’ll focus, and get insight into upcoming features. We’re looking forward to hearing from the community, so bring your questions!   TO GET ACCESS TO THIS EXCLUSIVE AMA: Kudo this post to reserve your spot! Reserve your spot now by kudoing this post.  Reservations will be prioritized on when your kudo for the post comes through, so don't wait! Click that "kudo button" today.   Invitations will be sent on April 2nd.Users posting Kudos after April 2nd at 9AM PDT may not receive an invitation but will be able to view the session online after conclusion of the event. Give your "kudo" today and mark your calendars for April 3, 2024 at 9:30 AM PDT and join us for an engaging and informative session!

Tuesday Tip: Unlocking Community Achievements and Earning Badges

TUESDAY TIPS are our way of communicating helpful things we've learned or shared that have helped members of the Community. Whether you're just getting started or you're a seasoned pro, Tuesday Tips will help you know where to go, what to look for, and navigate your way through the ever-growing--and ever-changing--world of the Power Platform Community! We cover basics about the Community, provide a few "insider tips" to make your experience even better, and share best practices gleaned from our most active community members and Super Users.   With so many new Community members joining us each week, we'll also review a few of our "best practices" so you know just "how" the Community works, so make sure to watch the News & Announcements each week for the latest and greatest Tuesday Tips!     THIS WEEK'S TIP: Unlocking Achievements and Earning BadgesAcross the Communities, you'll see badges on users profile that recognize and reward their engagement and contributions. These badges each signify a different achievement--and all of those achievements are available to any Community member! If you're a seasoned pro or just getting started, you too can earn badges for the great work you do. Check out some details on Community badges below--and find out more in the detailed link at the end of the article!       A Diverse Range of Badges to Collect The badges you can earn in the Community cover a wide array of activities, including: Kudos Received: Acknowledges the number of times a user’s post has been appreciated with a “Kudo.”Kudos Given: Highlights the user’s generosity in recognizing others’ contributions.Topics Created: Tracks the number of discussions initiated by a user.Solutions Provided: Celebrates the instances where a user’s response is marked as the correct solution.Reply: Counts the number of times a user has engaged with community discussions.Blog Contributor: Honors those who contribute valuable content and are invited to write for the community blog.       A Community Evolving Together Badges are not only a great way to recognize outstanding contributions of our amazing Community members--they are also a way to continue fostering a collaborative and supportive environment. As you continue to share your knowledge and assist each other these badges serve as a visual representation of your valuable contributions.   Find out more about badges in these Community Support pages in each Community: All About Community Badges - Power Apps CommunityAll About Community Badges - Power Automate CommunityAll About Community Badges - Copilot Studio CommunityAll About Community Badges - Power Pages Community

Tuesday Tips: Powering Up Your Community Profile

TUESDAY TIPS are our way of communicating helpful things we've learned or shared that have helped members of the Community. Whether you're just getting started or you're a seasoned pro, Tuesday Tips will help you know where to go, what to look for, and navigate your way through the ever-growing--and ever-changing--world of the Power Platform Community! We cover basics about the Community, provide a few "insider tips" to make your experience even better, and share best practices gleaned from our most active community members and Super Users.   With so many new Community members joining us each week, we'll also review a few of our "best practices" so you know just "how" the Community works, so make sure to watch the News & Announcements each week for the latest and greatest Tuesday Tips!   This Week's Tip: Power Up Your Profile!  🚀 It's where every Community member gets their start, and it's essential that you keep it updated! Your Community User Profile is how you're able to get messages, post solutions, ask questions--and as you rank up, it's where your badges will appear and how you'll be known when you start blogging in the Community Blog. 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.     Password Puzzles? No Problem! Find out how to sync your Azure AD password with your community account, ensuring a seamless sign-in. No separate passwords to remember! Job Jumps & Email Swaps Changed jobs? Got a new email? Fear not! You'll find out how to link your shiny new email to your existing community account, keeping your contributions and connections intact. Username Uncertainties Unraveled Picking the perfect username is crucial--and sometimes the original choice you signed up with doesn't fit as well as you may have thought. There's a quick way to request an update here--but remember, your username is your community identity, so choose wisely. "Need Admin Approval" Warning Window? If you see this error message while using the community, don't worry. A simple process will help you get where you need to go. If you still need assistance, find out how to contact your Community Support team. Whatever you're looking for, when it comes to your profile, the Community Account Support Knowledge Base article is your treasure trove of tips as you navigate the nuances of your Community Profile. It’s the ultimate resource for keeping your digital identity in tip-top shape while engaging with the Power Platform Community. So, dive in and power up your profile today!  💪🚀   Community Account Support | Power Apps Community Account Support | Power AutomateCommunity Account Support | Copilot Studio  Community Account Support | Power Pages

Super User of the Month | Chris Piasecki

In our 2nd installment of this new ongoing feature in the Community, we're thrilled to announce that Chris Piasecki is our Super User of the Month for March 2024. If you've been in the Community for a while, we're sure you've seen a comment or marked one of Chris' helpful tips as a solution--he's been a Super User for SEVEN consecutive seasons!   Since authoring his first reply in April 2020 to his most recent achievement organizing the Canadian Power Platform Summit this month, Chris has helped countless Community members with his insights and expertise. In addition to being a Super User, Chris is also a User Group leader, Microsoft MVP, and a featured speaker at the Microsoft Power Platform Conference. His contributions to the new SUIT program, along with his joyous personality and willingness to jump in and help so many members has made Chris a fixture in the Power Platform Community.   When Chris isn't authoring solutions or organizing events, he's actively leading Piasecki Consulting, specializing in solution architecture, integration, DevOps, and more--helping clients discover how to strategize and implement Microsoft's technology platforms. We are grateful for Chris' insightful help in the Community and look forward to even more amazing milestones as he continues to assist so many with his great tips, solutions--always with a smile and a great sense of humor.You can find Chris in the Community and on LinkedIn. Thanks for being such a SUPER user, Chris! 💪 🌠  

Find Out What Makes Super Users So Super

We know many of you visit the Power Platform Communities to ask questions and receive answers. But do you know that many of our best answers and solutions come from Community members who are super active, helping anyone who needs a little help getting unstuck with Business Applications products? We call these dedicated Community members Super Users because they are the real heroes in the Community, willing to jump in whenever they can to help! Maybe you've encountered them yourself and they've solved some of your biggest questions. Have you ever wondered, "Why?"We interviewed several of our Super Users to understand what drives them to help in the Community--and discover the difference it has made in their lives as well! Take a look in our gallery today: What Motivates a Super User? - Power Platform Community (microsoft.com)

March User Group Update: New Groups and Upcoming Events!

  Welcome to this month’s celebration of our Community User Groups and exciting User Group events. We’re thrilled to introduce some brand-new user groups that have recently joined our vibrant community. Plus, we’ve got a lineup of engaging events you won’t want to miss. Let’s jump right in: New User Groups   Sacramento Power Platform GroupANZ Power Platform COE User GroupPower Platform MongoliaPower Platform User Group OmanPower Platform User Group Delta StateMid Michigan Power Platform Upcoming Events  DUG4MFG - Quarterly Meetup - Microsoft Demand PlanningDate: 19 Mar 2024 | 10:30 AM to 12:30 PM Central America Standard TimeDescription: Dive into the world of manufacturing with a focus on Demand Planning. Learn from industry experts and share your insights. Dynamics User Group HoustonDate: 07 Mar 2024 | 11:00 AM to 01:00 PM Central America Standard TimeDescription: Houston, get ready for an immersive session on Dynamics 365 and the Power Platform. Connect with fellow professionals and expand your knowledge. Reading Dynamics 365 & Power Platform User Group (Q1)Date: 05 Mar 2024 | 06:00 PM to 09:00 PM GMT Standard TimeDescription: Join our virtual meetup for insightful discussions, demos, and community updates. Let’s kick off Q1 with a bang! Leaders, Create Your Events!  Leaders of existing User Groups, don’t forget to create your events within the Community platform. By doing so, you’ll enable us to share them in future posts and newsletters. Let’s spread the word and make these gatherings even more impactful! Stay tuned for more updates, inspiring stories, and collaborative opportunities from and for our Community User Groups.   P.S. Have an event or success story to share? Reach out to us – we’d love to feature you!

Users online (5,008)