bigskysoftware / bigskysoftware/htmx-extensions

Enhancement request: WebSocket extension should handle file uploads

Open
#17 1 comment 0 reactions 0 assignees View on GitHub
enhancement
Dominant language
JavaScript
Stars
284
Forks
88
PR merge metrics
No merged PRs in 30d

Description

The WebSocket extension currently does not handle file uploads.

## To reproduce

Submit a form via WebSocket that has a file input:

```html


Upload

```

## What should happen

You should get the serialised contents of the file in a field called `fileToUpload`.

## What actually happens

As file upload functionality is not currently implemented, you get an empty object instead, along with the standard headers:

```js
{
fileToUpload: {},
HEADERS: {

}
}
```

## Implementation suggestion

The file’s contents could be read in using the [File Reader API](https://developer.mozilla.org/en-US/docs/Web/API/FileReader) and serialised to the JSON object.

Note that including the files contents in the JSON will not be the most performant option, especially for larger files, but I’m not sure what else can be done here while still keeping things easy to use. (Open to ideas) :)

## Workaround

You should be able to implement this manually in your [`htmx:wsConfigSend` handler](https://github.com/bigskysoftware/htmx-extensions/blob/main/src/ws/README.md#event---htmxwsconfigsend-htmxwsconfigsend).

Contributor guide

Open the contributing guide

Assessment

This issue has not been assessed yet.

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.