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

Using the HTTP (Premium) Connector inside Microsoft Flows, how do I POST (send) a file from SharePoint Library to external REST API?

Using Microsoft Flows, I need to send over (transfer/upload) the FILES from the SharePoint Library to the outside/external Server via REST API. I suppose I need to use the "HTTP" (Premium) connector for this.

 

But how do I make use of this "HTTP" connector to POST (send) files? I know it is part of how HTTP POST works. But I still cannot figure out how to attach files inside the Microsoft Flow's "HTTP" connector.

 

Can someone please help me on this? Thanks much.

 

Screenshot 2022-07-28 at 12.22.50 PM.png

1 ACCEPTED SOLUTION

Accepted Solutions
eric-cheng
Solution Sage
Solution Sage

Hi @anonymust ,

 

Please check out the below two links which should get you on the right track on how to format your request body for the multipart/form-data content type.

 

Using Multipart/Form-Data in a Power Automate or Logic Apps HTTP Action – Clavin's Blog (wordpress.c...

 

Using the HTTP Action to POST Multipart Form Data in Power Automate & Logic Apps – William's IT Blog...

 

--------------------------------------------------------------------------
If I have answered your question, please mark my post as a solution
If you have found my response helpful, please give it a thumbs up

Connect on LinkedIn

 

 

 

 

 

 

 

 

 

View solution in original post

4 REPLIES 4
eric-cheng
Solution Sage
Solution Sage

Hi @anonymust ,

 

Depending on the API, you may need to send the file as a base64 string. 

 

The API you are calling will have a schema or a swagger/open api definition which tells you what inputs are required to be passed in.  Do you have the details for this?  

 

The below is how you would get a file from a document library and then convert it to base64 using an expression.  However, as mentioned, you still need to format the request body.

 

ericcheng_0-1659002063555.png

 

--------------------------------------------------------------------------
If I have answered your question, please mark my post as a solution
If you have found my response helpful, please give it a thumbs up

Connect on LinkedIn

 

 

 

Hi @eric-cheng thanks much for helping.

 

REST API is actually on our own servers with the simple PHP API codes which takes file attached as in "multipart/form-data".

 

I could submit the HTTP POST requests using simple CURL command, like:

 

curl -i -u username:password -X POST -H "Content-Type: multipart/form-data" -F "file=@sample.png" https://api.ourserver.com/upload/

 

(I can make the exact same HTTP POST request with "multipart/form-data" using the Postman as well.)

 

And then I could simply receive those attached files from our PHP REST API Servers, using something like:

 

move_uploaded_file( $_FILES['file']['tmp_name'], '/usr/uploads/'.$_FILES['file']['name'] );

 

All those files got saved on our Servers.

 

But then from inside "HTTP" connector in Microsoft Flow, I don't know how to submit POST requests with "multipart/form-data" (or) to mimic such simple CURL command. I know how to put correct Headers there. But I'm confused on how to craft it's "Body" part into "multipart/form-data" equivalent.

 

Hope you can advise on this. Thank you.

eric-cheng
Solution Sage
Solution Sage

Hi @anonymust ,

 

Please check out the below two links which should get you on the right track on how to format your request body for the multipart/form-data content type.

 

Using Multipart/Form-Data in a Power Automate or Logic Apps HTTP Action – Clavin's Blog (wordpress.c...

 

Using the HTTP Action to POST Multipart Form Data in Power Automate & Logic Apps – William's IT Blog...

 

--------------------------------------------------------------------------
If I have answered your question, please mark my post as a solution
If you have found my response helpful, please give it a thumbs up

Connect on LinkedIn

 

 

 

 

 

 

 

 

 

Hi @eric-cheng 

 

I followed your first link and it worked! That was amazing!

 

Thank you so much for your kind helps!

Helpful resources

Announcements
October Events

Mark Your Calendars

So many events happening this month - don't miss out!

 WHAT’S NEXT AT MICROSOFT IGNITE 2022

WHAT’S NEXT AT MICROSOFT IGNITE 2022

Explore the latest innovations, learn from product experts and partners, level up your skillset, and create connections from around the world.

Register for a Free Workshop.png

Register for a Free Workshop

Learn to digitize and optimize business processes and connect all your applications to share data in real time.

Users online (2,694)