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

vaidyarm,

You can do this with a triggered task, but need to make sure there is only a binary view open, otherwise it will fail with the error:

Document input views only accept JSON-encoded data

SnapLogic has two types of input views: document and binary. The document input views are used for structured or semi-structured data like Json, XML, CSV, etc. Document input views are represented by a Snap with an open circle like this.

image

For your use case, the request will be multipart-form-data and so the pipeline should have a binary input view. Specifically you should use a Multipart Reader that will be able to extract the binary data from the POST request. The binary input view is an open diamond.

image

Hereโ€™s an example of a Pipeline that takes the POSTed file and stores it in SLFS using the Multipart Reader and the File Writer. You can try it out by importing this pipeline, creating a triggered task, and then using Postman/curl to send a file to the task endpoint. You should see the file you sent written to a file named โ€˜attachment.txtโ€™ in the same project as the pipeline.

post-file-example_2019_10_04.slp (4.3 KB)

that really helped !!! i am able to transfer all kind of posted files now wherever I need to send it.
but there is one thing that i have to pass in API requested along with the attachment, the name of the file in the query field. then i map this pipeline parameter to the filename in file writer
is there a way where i can simply provide attachment and auth details to the REST POST API and pipeline should extract the name from it in form of some variable which we can map as the file name in file writer snap ?

tlikarish
Employee
Employee

Not really at the moment โ€“ although there is now an enhancement ticket to improve the Multipart Read so that it could do things like this. Iโ€™ll try and keep you updated about when it goes into development.

For now, another option would be to write the file to a โ€œtemporaryโ€ location and then have a separate pipeline that moves the pipeline to the final location. Then the API would require two POST calls, one to upload the file and the other that would take the file path and other things needed to write it to the final location that would โ€œcommitโ€ the file.

let us know such updates.

however, as you said we can write file to temp location like sldb, even for that we would require some parameter name to map as the filename.

Ex: the pipeline you shared is writing file as attachment.txt, not the name of the actual sent attachment, how this can be handled if the name of file need to be the same in post request?
Also, I tried with making task as ultra and pass parameter, ultra is not capturing the parameter in triggers