cancel
Showing results for 
Search instead for 
Did you mean: 
Reply
cruizr-cinepoli
Level: Powered On

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
SamPo
Level 8

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

15 REPLIES 15
Super User
Super User

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!


cruizr-cinepoli
Level: Powered On

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

 

 

http.PNGHTTPpostman.PNGPostmanhttp sending.PNGhttp Sendingresponse.PNGhttp 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!

 

 


 

SamPo
Level 8

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

cruizr-cinepoli
Level: Powered On

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

 

 

Maria_Geek
Level: Powered On

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?

cruizr-cinepoli
Level: Powered On

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
Maria_Geek
Level: Powered On

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

Maria_Geek
Level: Powered On

Re: Send file with HTTP Rest

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

Maria_Geek
Level: Powered On

Re: Send file with HTTP Rest

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

karlosarr
Level: Power Up

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']}
      }
    }
  ]
}
Maria_Geek
Level: Powered On

Re: Send file with HTTP Rest

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

SamPo
Level 8

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.

Maria_Geek
Level: Powered On

Re: Send file with HTTP Rest

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

SamPo
Level 8

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

Maria_Geek
Level: Powered On

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.

Helpful resources

Announcements
thirdimage

Power Automate Community User Group Member Badge

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

firstImage

Incoming: New and improved badges!

We've given our badges an overhaul and also added some brand new ones!

fifthimage

Microsoft Learn

Learn how to build the business apps that you need.

sixthImage

Power Platform World Tour

Find out where you can attend!

seventhimage

Webinars & Video Gallery

Watch & learn from the Power Automate Community Video Gallery!

Top Kudoed Authors
Users Online
Currently online: 167 members 5,371 guests
Please welcome our newest community members: