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

Send file with HTTP Rest

Hi!

I am receiving an email with or without an attachment to create an issue in Jira, then send a request to Jira to upload the attachment. In Postman it works but in Flow I can not upload the file.

 

Captura de pantalla 2019-03-29 a la(s) 18.29.05.pngSend postman with fileCaptura de pantalla 2019-03-29 a la(s) 18.08.22.pngMy FlowCaptura de pantalla 2019-03-29 a la(s) 18.08.40.pngConditionCaptura de pantalla 2019-03-29 a la(s) 18.08.57.pngTesting requestCaptura de pantalla 2019-03-29 a la(s) 18.10.27.pngTesting respondeCaptura de pantalla 2019-03-29 a la(s) 18.10.37.pngTesting responde

1 ACCEPTED SOLUTION

Accepted Solutions
Highlighted
Impactful Individual
Impactful Individual

Re: Send file with HTTP Rest

@cruizr-cinepoli 

 

Use this:

 

Screenshot 2019-04-09 at 21.png

 

{
  "$content-type": "multipart/form-data",
  "$multipart": [
    {
      "headers": {
        "Content-Disposition": "form-data; name=\"file\"; filename=XXXXX"
      },
      "body": XXXXX
    }
  ]
}

The 'body' should be the file content you get when retrieving the file.

 

Sam

View solution in original post

16 REPLIES 16
Highlighted
Power Participant
Power Participant

Re: Send file with HTTP Rest

Hey @cruizr-cinepoli 

 

I found the issue.

 

In content put this expression:

 

item()?['ContentBytes']

It will send only the file, you are sending all informations of file, like name, type and etc.

 

Anotação 2019-04-05 204623.jpg

 

Best Regards,

Gustavo Moraes

Community Super User
If this post helps, then please consider Accept it as the solution to help the other members find it more quickly. And give me a kudo to make me more happy!

 

 


Did I answer your question? Mark my post as a solution!

Gustavo Moraes, o astronauta brasileiro do Flow!


Highlighted
Frequent Visitor

Re: Send file with HTTP Rest

Hi @gamoraesthanks for your answer

 

I still have problems, I built it in the following way, but this message comes back:

 

 

org.apache.commons.fileupload.FileUploadException: Stream ended unexpectedly

 

 

HTTPHTTPPostmanPostmanhttp Sendinghttp Sendinghttp responsehttp response


@gamoraes wrote:

Hey @cruizr-cinepoli 

 

I found the issue.

 

In content put this expression:

 

item()?['ContentBytes']

It will send only the file, you are sending all informations of file, like name, type and etc.

 

Anotação 2019-04-05 204623.jpg

 

Best Regards,

Gustavo Moraes

Community Super User
If this post helps, then please consider Accept it as the solution to help the other members find it more quickly. And give me a kudo to make me more happy!

 

 


 

Highlighted
Impactful Individual
Impactful Individual

Re: Send file with HTTP Rest

@cruizr-cinepoli 

 

Use this:

 

Screenshot 2019-04-09 at 21.png

 

{
  "$content-type": "multipart/form-data",
  "$multipart": [
    {
      "headers": {
        "Content-Disposition": "form-data; name=\"file\"; filename=XXXXX"
      },
      "body": XXXXX
    }
  ]
}

The 'body' should be the file content you get when retrieving the file.

 

Sam

View solution in original post

Highlighted
Frequent Visitor

Re: Send file with HTTP Rest

Thx @SamPo for your help

 

{
  "$content-type": "multipart/form-data",
  "$multipart": [
    {
      "headers": {
        "Content-Disposition": "form-data; name=\"file\"; filename=@{items('Aplicar_a_cada_uno')?['Name']}"
      },
      "body": {
        "$content-type": "@{items('Aplicar_a_cada_uno')?['ContentType']}",
        "$content": @{items('Aplicar_a_cada_uno')?['ContentBytes']}
      }
    }
  ]
}

 

 

Highlighted
Helper I
Helper I

Re: Send file with HTTP Rest

Hi @SamPo I found this code very helpful.  But now I need to include a second file.  How would I do that?

Highlighted
Frequent Visitor

Re: Send file with HTTP Rest

Hi @Maria_Geek 

Try this:

 

{
  "$content-type": "multipart/form-data",
  "$multipart": [
    {
      "headers": {
        "Content-Disposition": "form-data; name=\"file\"; filename=@{items('Aplicar_a_cada_uno')?['Name']}"
      },
      "body": {
        "$content-type": "@{items('Aplicar_a_cada_uno')?['ContentType']}",
        "$content": @{items('Aplicar_a_cada_uno')?['ContentBytes']}
      },
//second { "headers": { "Content-Disposition": "form-data; name=\"file2\"; filename=@{items('Aplicar_a_cada_uno')?['Name']}" }, "body": { "$content-type": "@{items('Aplicar_a_cada_uno')?['ContentType']}", "$content": @{items('Aplicar_a_cada_uno')?['ContentBytes']} } } } ] }
Highlighted
Helper I
Helper I

Re: Send file with HTTP Rest

Thanks @cruizr-cinepoli for the quick response.  You are making my Friday great.  I entered what I thought was exactly what you sent.  Here's a copy.  Still it simply says it's invalid.  I have tried several variations.

 

codecopy.png

Highlighted
Helper I
Helper I

Re: Send file with HTTP Rest

The code is good if I do 1, but the minute I add the second it's invalid.

Highlighted
Helper I
Helper I

Re: Send file with HTTP Rest

I did add the missing } on the bottom section.  I'm just not sure it likes 2 files.

Highlighted
New Member

Re: Send file with HTTP Rest

Use the ContentBytes from file:

 

Captura de Pantalla 2019-04-27 a la(s) 11.57.53.png

 

Sintaxis:

 

{
  "$content-type": "multipart/form-data",
  "$multipart": [
    {
      "headers": {
        "Content-Disposition": "form-data; name=\"file\"; filename=@{items('Aplicar_a_cada_uno')?['Name']}"
      },
      "body": {
        "$content-type": "@{items('Aplicar_a_cada_uno')?['ContentType']}",
        "$content": @{items('Aplicar_a_cada_uno')?['ContentBytes']}
      }
    }
  ]
}
Highlighted
Helper I
Helper I

Re: Send file with HTTP Rest

Yes, this works great for a single file.  How about for 2 files?

Highlighted
Impactful Individual
Impactful Individual

Re: Send file with HTTP Rest

@Maria_Geek Honestly, I just use an apply to each to make multiple calls. If I have 2 files then I make 2 seperate API calls and use the 'body' and 'name' variables to set the name and content of the file.

Highlighted
Helper I
Helper I

Re: Send file with HTTP Rest

Yea, but my API is a fax and I need it to go with a cover sheet.

Highlighted
Impactful Individual
Impactful Individual

Re: Send file with HTTP Rest

@Maria_Geek In this case I would set up a new flow triggered by HTTP then use Postman to send a request to that flow with 2 files - Use the Postman files feature to attach both files to a single request.

 

Then from the run log of the flow you can see how the request is received and this should give you an idea of how to setup your call. Essentially this gives you the best way to see how postman actually sends the data which you can then copy.

 

Hope this helps,

Sam

Highlighted
Helper I
Helper I

Re: Send file with HTTP Rest

Thanks @SamPo .  That helped me find all the commas and squigly brackets I needed.  I truly appreciate it.

 

New post coming.

Highlighted
Frequent Visitor

Re: Send file with HTTP Rest

This method saved me lots of trouble that I had. Thanks a lot @SamPo !

Helpful resources

Announcements
firstImage

Super User Program Update

Three Super User rank tiers have been launched!

firstImage

Power Platform 2020 release wave 2 plan

Features releasing from October 2020 through March 2021

firstImage

New & Improved Power Automate Community Cookbook

We've updated and improved the layout and uploading format of the Power Automate Cookbook!

thirdimage

Power Automate Community User Group Member Badge

Fill out a quick form to claim your user group badge now!

Top Kudoed Authors
Users online (6,620)