# mod\_fileuploader

Source: https://zotonic.com/docs/2241/mod_fileuploader

URI: https://zotonic.com/id/2241

Language: en



Upload files using a parallel web worker.

This module provides a web worker and server logic to quickly upload files.

The web worker sends files in 128KB parts to the server, the server recombines all parts to a single file. The web worker is using multiple parallel uploaders to make optimal use of the available bandwidth.

Files are sent to the webworker on the topic `model/fileuploader/post/new`:

```javascript
let f = document.getElementById("upload_file").files[0];

let msg = {
    files: [
        {
            name: "resultname",             // The name used in the ready message
            upload: "WZkhXoaMwrK2StUHmdpp", // Unique name to register the upload process. It's generated by the server if undefined
            file: f                         // Must be a File object
        }
    ],

    start_topic: "bridge/origin/foo", // Receives the upload metadata when the upload starts

    ready_msg: {
        foo: "bar",                 // Anything you want to send if all files are uploaded
        files: []                   // This will be set by the worker
    },
    ready_topic: "bridge/origin/foo/bar",

    progress_msg: {
        form_id: "some-element-id",
        is_auto_unmask: true,
        percentage: 0               // Will be set by the uploader, 100 when ready
    },
    progress_topic: "zotonic-transport/progress"
};
cotonic.broker.publish("model/fileuploader/post/new", msg);
```

The files received with the `ready_msg` on the `ready_topic` will be:

```javascript
{
    name: "resultname",             // Name provided in the upload
    upload: "WZkhXoaMwrK2StUHmdpp"  // Unique name to use with z_fileuploader:status/1
}
```

An upload can be canceled by publishing the topic `model/fileuploader/post/delete/+name`, where the name is the unique name generated by the server.

Accepted Events
---------------

This module handles the following notifier callbacks:

- `observe_validate_query_args`: Replace all #fileuploader\{\} records with #upload\{\} and the uploaded file using `z_fileuploader:status`.

Delegate callbacks:

License: 

Attribution: 

Related resources: https://zotonic.com/api/agent/related/2241?language=en


## API access

- [API help](<https://zotonic.com/api-help>)
- [OpenAPI specification](<https://zotonic.com/openapi.json>)
- [This resource as JSON](<https://zotonic.com/api/agent/resource/2241?language=en>)
