cancel
Showing results for 
Search instead for 
Did you mean: 

How to receive file through snaplogic API call

vaidyarm
Contributor

hi

we have a requirement to receive a file in snaplogic where we have to provide API URL to an external team. that team will do REST post along with file attached in POST request. we are supposed receive the file and store it. we tried a number of ways but it’s not working.

we sent a text file through Postman on API POST request as an attachment, but that pipeline failed with error msg as below.

“Document input views only accept JSON-encoded data”

let us know if there is a way to consume a file from such REST POST request with files attached to it

8 REPLIES 8

tlikarish
Employee
Employee

hey – originally I was thinking that you could just write to that constant file location with maybe a timestamp or uuid to make it unique. If you add an output view to the FileWriter, then it’ll respond to the request with the file locations of where things were written. Alternatively you could also use a regex to read the file names, or other parts of the content-disposition header, that are passed into your task and re-use those.

Here’s an example pipeline that shows how that second approach would work.
post-variable-filename-example_2019_10_10.slp (6.1 KB)

Rudhiran
New Contributor

HI @tlikarish  Above code isn't working for me. I tried to send .xlxs  and .csv file but in mapper snap $['content-disposition'].match('filename=\"(.*)\"')[1] getting error that content-disposition not found

Appreciate your help on this issue

Anyone who know the solution can help us - appreciate your help 

Thanks 

Hi Rudhiran -- the double quotes were escaped in my example. Not sure where those came from, but could you try this expression, with backslashes removed, in your mapper and see if it will work for you?

$['content-disposition'].match('filename="(.*)"')[1]

 

HI @tlikarish , 

Multipart reader gives response only Content type and Content - Not the  content-disposition

So we're getting error in mapper that 

Cannot invoke a method on a null value

 

Resolution:
Please check expression syntax

 

Reason:
Value referenced in the sub-expression '$.get('content-disposition').match('filename="(.*)"')' is null
 
Appreciate your help on this issue