How do I attach a file (like curl -F file=@{path/to/file.csv} to a Jitterbit HTTP POST Operation?

1.1k views Asked by At

How would I go about translating the following curl command to a Jitterbit operation?

curl -i -u username:password -X POST -F file=@/path/to/file.csv 
https://website.com/api/filepost

Currently I have my Operation structured as follows:

enter image description here

  1. Script:

    $jitterbit.target.http.form_data = true; $jitterbit.target.http.form_data.filename = "file.csv"; $jitterbit.target.http.form_data.name = "file";

  2. Source A CSV file without headers, which matches the API's specifications (sent the same file successfully via curl)

  3. Transformation: Text to Text - both source and target use the same file format as the Source file

  4. API Endpoint enter image description here

Currently I authenticate successfully, but I get a 400/Bad Request error message saying "No file attached".

Full error message:

The operation "2. POST Preapplicants - CSV to API" failed.

Fatal Error
Failed to post to the url 'https://website.com/api/filepost’. 
The last (and probably most relevant) error was: The server 
returned HTTP Status Code : 400 Bad Request  Error is: The 
request could not be processed by the server due to invalid 
syntax. Headers sent by the server: HTTP/1.1 400 Bad Request 
Server: nginx/1.10.3 (Ubuntu) Content-Type: application/json 
Transfer-Encoding: chunked Connection: keep-alive Cache-Control: 
no-cache Date: Tue, 12 Sep 2017 18:55:38 GMT  The response was: 
{"message":"No file attached."}
2

There are 2 answers

0
Brock Elgart On

I solved this problem by doing the following: 1. Changing from a transformation operation to an archive operation (using the same source, target, and script) 2. Changing the content-type of my HTTP connection to multipart/form-data (the default content-type passed by curl)

0
Tdubs On

you can do it that way. what I did was use a file list operation stored that into an array then uses a Base64EncodeFile() function to upload the file