cancel
Showing results for 
Search instead for 
Did you mean: 
Reply
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

@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
Memorable Member
Memorable Member

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

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

@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

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

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

Highlighted

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

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

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

Highlighted

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

Highlighted

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

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

Highlighted
Impactful Individual
Impactful Individual

@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

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

Highlighted
Impactful Individual
Impactful Individual

@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

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

 

New post coming.

Highlighted

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

Helpful resources

Announcements
Community Conference

Power Platform Community Conference

Check out the on demand sessions that are available now!

Power Platform ISV Studio

Power Platform ISV Studio

ISV Studio is designed to become the go-to Power Platform destination for ISV’s to monitor & manage published applications.

Top Solution Authors
Top Kudoed Authors
Users online (11,201)