Add support for uploading files to http client

Created on 15 December 2024, 4 days ago

Problem/Motivation

I'm using the http client action in a model to post to Mastodon, and this is working. Now I want to upload an image, with alt text.

Proposed resolution

Add a "File" serialization that uses Guzzle's "multipart" support to post a file to a remote service.

User interface changes

Need to provide documentation for how to pass in the file to upload, as well as other metadata about the file.

Using the Mastodon service as an example, we want to post 3 items in the multipart section:

"name" - "file" -- the field name for the multi-part form. Mastodon expects this to be "file" but other APIs might need a different field name.

"contents" - a file or stream pointer -- this is what Guzzle requires to have the file contents or a handle.

"description" - Mastodon uses this as an alt tag for the uploaded image.

API changes

To get this working, I've added an option to the "data_serialization" field, for "file". When that is selected, the "data" field is run through the YAML parser - the value of "file" is passed into fopen, and the value of "description" is passed to description.

Data model changes

Right now, no other changes to the data model are needed -- but if there are other values to pass to Guzzle's multipart uploads (e.g. pass other field values, pass multiple files) may need some improvements to the UI and data model.

✨ Feature request
Status

Active

Version

2.0

Component

Code

Created by

πŸ‡ΊπŸ‡ΈUnited States freelock Seattle

Live updates comments and jobs are added and updated live.
Sign in to follow issues

Comments & Activities

Production build 0.71.5 2024