Convertigo Public Knowledge base

Urlmapper upload/download file

To upload a file from a sequence you need:

  • A sequence variable witth “is a file upload“ property set to true (‘file’ for example):

 

The file is sent as a Multipart file via the Sequence and is copied to the system temporary folder of the Convertigo Server.

It can be accessed while the sequence is executed (JS scope variable ‘file’ or via InputVars source Step). It is up to you to manipulate de file as you need with Sequence’ Steps.

The file is automatically deleted upon Sequence termination.

  • An UrlMapper component with a PostOperation that contains a FormParameterInput type” ‘File’ and “Mapped variable name“ set to the sequence variable name ('file' in this case).

 

Urlmapper call example via curl :

$ curl -v -X POST "http://localhost:18080/convertigo/openapi/upload/v1" -F "file=\"C:\Convertigo\Studio 8.1.0\workspace\lib_fill_odt_pdf\outputs\out_XXX_YYY.pdf\";filename=out_XXX_YYY.pdf" Note: Unnecessary use of -X or --request, POST is already inferred. * Trying 127.0.0.1:18080... % Total % Received % Xferd Average Speed Time Time Time Current Dload Upload Total Spent Left Speed 0 0 0 0 0 0 0 0 --:--:-- --:--:-- --:--:-- 0* Connected to localhost (127.0.0.1) port 18080 (#0) > POST /convertigo/openapi/upload/v1 HTTP/1.1 > Host: localhost:18080 > User-Agent: curl/7.84.0 > Accept: */* > Content-Length: 275 > Content-Type: multipart/form-data; boundary=------------------------6d1e97bf8fe2cb64 > } [275 bytes data] * We are completely uploaded and fine * Mark bundle as not supporting multiuse < HTTP/1.1 200 < Set-Cookie: JSESSIONID=BD8214220FD5ACDCD51296E6E5B59B25; Path=/convertigo; HttpOnly < Content-Type: application/json;charset=UTF-8 < Content-Length: 156 < Date: Thu, 15 Dec 2022 09:22:53 GMT < { [156 bytes data] 100 431 100 156 100 275 8912 15710 --:--:-- --:--:-- --:--:-- 25352{ "inputVars": { "file": "C:\\Users\\grego\\AppData\\Local\\Temp\\c8o-multipart-files10844672770205115294.tmp\\1\\out_XXX_YYY.pdf" }, "element": "OK" } * Connection #0 to host localhost left intact

 

To initiate a Download from a Sequence or a transaction, you need to satisfy 2 conditions:

  1. The Sequence/Transaction must be called with .bin requester (not in .json or .pxml)

  2. The Sequence/Transaction must return an attachment response with specific attributes.

{ "attachment": { "text": "", "attr": { "content-length": "4802", "local-url": "C:\\Convertigo\\Studio 8.1.0\\workspace\\urlmapper_download_sample/files/c8o.png", "name": "c8o.png", "type": "attachment" } } }

The DonwloadHttp sample project illustrates this possibility through a transaction that directly download a file via the __uri variable and whose value is an absolute URL.

GET REST call of the project in the Convertigo Studio:

http://localhost:18080/convertigo/projects/DownloadHttp/.bin?__uri=https://uploads-ssl.webflow.com/62d55bc018a5be3f0b91fcf3/62d55bc018a5be089691fd24_Color%3DBlueConvertigo.png

The Transaction converts the file to Base64 string before proposing it for download, it is not recommended for large files size.

The Urlmapper only calls Sequences by .json or .pxml. To circumvent this, the sequence is using a trick in a SequenceJS Step to redirect the call to another sequence in .bin requester.

The urlmapper_download_sample sample project illustrates this operation via a GET operation downloadFile mapped on /uds/file/{file_id}

the download Sequence is called in a classic manner (.json) et it redirects the call towards the attach Sequence in .bin mode, generating the attachment response and a link to the local file relative to the project.

 

 

(c) Convertigo 2023 https://www.convertigo.com