Omniscope Custom Blocks › Outputs/Multi-Form-Upload

Multipart Form Upload

Posts files to an HTTP endpoint as multipart/form-data, one request per file, and records each response's status and body.

Outputs › API Python

Open the demo in Omniscope Download demo.ioz Sample data: placeholder.csv Sample data: upload-list.csv Source on GitHub

Omniscope custom block · Outputs

A service that takes files through a web form or a file-upload API? Send each file from the workflow and keep a record of every answer.

Python · requests, pandas · requests installed on first run if missing

The problem it solves

Invoices to an accounts system, signed documents to an archive, daily extracts to a partner's intake: many services accept files only through a multipart upload, the request a browser sends when a form has a file field. Sending them by hand means logging in and attaching each file; scripting it means code outside the workflow, and no record of what was accepted.

This block posts each file listed in its input to the endpoint, one request per file, and outputs the input records with the status, the response and any error.

How it works

What goes in

Upload list (upload-list.csv, paths added)

Five invented invoices, each a small CSV file in sample-data/files/. INV-1005 is listed but has no file, to show what a missing file looks like.

Invoice File name File path
INV-1001 INV-1001.csv /data/omniscope/outgoing/invoices/INV-1001.csv
INV-1002 INV-1002.csv /data/omniscope/outgoing/invoices/INV-1002.csv
INV-1003 INV-1003.csv /data/omniscope/outgoing/invoices/INV-1003.csv
INV-1004 INV-1004.csv /data/omniscope/outgoing/invoices/INV-1004.csv
INV-1005 INV-1005.csv /data/omniscope/outgoing/invoices/INV-1005.csv

The options

Option Demo setting What it does
Upload URL https://uploads.example.com/api/files The endpoint each file is posted to.
File to upload (no input) (empty) A single file, used when nothing is connected.
File path field File path The field with each record's file path.
Form field name file The multipart field that carries the file.
Extra form fields (empty) name=value lines sent with every file, such as folder=invoices.
Headers (empty) Name: value lines, such as Accept: application/json. Saved as plain text: put a secret in Authorization, which is kept as a password.
Authorization (a token) The Authorization header, such as Bearer and a token.

What comes out

Results

Invoice File name HTTP status Response Error
INV-1001 INV-1001.csv 201 {"status": "received", "file": "INV-1001.csv", "id": "upl-0001"}
INV-1002 INV-1002.csv 201 {"status": "received", "file": "INV-1002.csv", "id": "upl-0002"}
INV-1003 INV-1003.csv 201 {"status": "received", "file": "INV-1003.csv", "id": "upl-0003"}
INV-1004 INV-1004.csv 201 {"status": "received", "file": "INV-1004.csv", "id": "upl-0004"}
INV-1005 INV-1005.csv File not found: /data/omniscope/outgoing/invoices/INV-1005.csv

The File path field is kept too. The responses are invented answers from the tests; a real endpoint answers in its own format.

Where it pays off

Finance: Invoices and statements to another system

Send the invoice or remittance files a workflow produces to an accounts or payments service that takes uploads.

Document management: Filing reports

Upload the PDFs printed from a Report, one per client or region, to a document store, with the folder as an extra form field.

Data exchange: Partner and regulator intakes

Post daily or monthly extract files to a partner's or regulator's upload endpoint, and keep the receipt it returns.

Operations: Feeding other tools

Push files to a ticketing, e-signature or workflow tool's upload API, with its token in the Authorization option.

Use cases describe typical scenarios and are illustrative; the sample data is invented.

Why do this in Omniscope

How it fits into an Omniscope workflow

File Attributes (the outgoing folder) or a PDF-printing block → Formula (file path) → Multipart Form Upload → Validate data (no errors) → Report

Join the results back to the source records on the file path to report which were accepted.

Try it

  1. Open the demo project (demo.iox on the demo server, or import demo.ioz from this folder). It holds the Multipart Form Upload block with an example address (not run) and a File block with placeholder.csv, the results the block gives for the invented answers in its tests.
  2. The question: which invoices were accepted, and which need attention?
  3. Follow the File block into the rest of the workflow: 4 records with status 201 and 1 with an error.
  4. To use it for real: enter your endpoint's URL and any headers or token, connect your list of files, run the block and connect its output where the File block was.

Running in Omniscope

Omniscope workflow
Omniscope workflow

The demo project's workflow: the placeholder data, the block, and a Validate data check on the output.

Language and libraries

Python, with requests (Apache License 2.0) and pandas (BSD 3-Clause).

pandas is part of Omniscope's Python environment. requests is listed in the block's dependencies, so Omniscope installs it with pip on first run if it is missing.

Tested

The block is covered by automated tests that check the requests it would send, against a fake endpoint (no live calls): one request per record, the multipart body (field name, file name, content type, file contents), headers, the Authorization value and extra form fields, the single-file mode, rejected uploads and connection failures, long responses, missing files and paths, empty input, option checks, and 2,000 files.

Reference

Fields it reads

NameTypeWhat it does
File path fieldFieldWith an input connected: the field holding each record's file path on the server. One request per record.

Options

NameTypeWhat it does
Upload URLTextThe endpoint to POST each file to, starting with http:// or https://.
File to upload (no input)FileThe file to upload when no input is connected. With an input, the File path field is used instead.
Form field nameTextThe name of the multipart field that carries the file. Most endpoints expect file.
Extra form fieldsTextOptional fields sent with every file, one per line as name=value, for example folder=invoices.
HeadersTextOptional HTTP headers, one per line as Name: value, for example Accept: application/json. Saved as plain text in the project: put a secret in Authorization instead.
AuthorizationPasswordOptional value of the Authorization header, such as Bearer followed by a token. Kept as a password.

Outputs

OutputWhat it holds
ResultsOne record per file: the input fields (or File path), HTTP status, Response (the body, truncated) and Error (empty when the upload succeeded).