cancel
Showing results for 
Search instead for 
Did you mean: 
Reply
Anonymous
Not applicable

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
Impactful Individual
Impactful Individual

@Anonymous 

 

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

20 REPLIES 20
gamoraes
Memorable Member
Memorable Member

Hey @Anonymous 

 

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!


Anonymous
Not applicable

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 @Anonymous 

 

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
Impactful Individual
Impactful Individual

@Anonymous 

 

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

Anonymous
Not applicable

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

 

 

Anonymous
Not applicable

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

Anonymous
Not applicable

Hi @Anonymous 

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']} } } } ] }
Anonymous
Not applicable

Thanks @Anonymous 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

Anonymous
Not applicable

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

Anonymous
Not applicable

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

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']}
      }
    }
  ]
}
Anonymous
Not applicable

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

SamPo
Impactful Individual
Impactful Individual

@Anonymous 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.

Anonymous
Not applicable

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

SamPo
Impactful Individual
Impactful Individual

@Anonymous 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

Anonymous
Not applicable

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

 

New post coming.

fatih_dur
Frequent Visitor

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

FoDelement
Continued Contributor
Continued Contributor

@SamPo  How would you accomplish this with a custom connector? 

SamPo
Impactful Individual
Impactful Individual

@FoDelement In theory this would be the same as any other custom connector. At the end of the day this is just using some specific headers and specific JSON format but it's still a standard JSON that you should be able to build in the custom connector editor. I've never tried it myself but don't see any reason why it shouldn't work.

FoDelement
Continued Contributor
Continued Contributor

Thank you! @SamPo  I created my own topic because I can't seem to get mine to work. I am trying either a custom connector or the Azure HTTP request. 

Helpful resources

Announcements
Process Advisor

Introducing Process Advisor

Check out the new Process Advisor community forum board!

MPA User Group

Welcome to the User Group Public Preview

Check out new user group experience and if you are a leader please create your group

V3_PVA CAmpaign Carousel.png

Community Challenge - Giveaways!

Participate in the Power Virtual Agents Community Challenge

Carousel 2021 Release Wave 2 Plan 768x460.jpg

2021 Release Wave 2 Plan

Power Platform release plan for the 2021 release wave 2 describes all new features releasing from October 2021 through March 2022.

Top Solution Authors
Top Kudoed Authors
Users online (2,249)