File Uploads
Basic File Upload
CBWIRE makes uploading and storing files easy.
Here's an example of a simple Wire that handles uploading a photo:
Handling file inputs is no different than handling any other input type with CBWIRE. Add wire:model
to the <input>
tag and CBWIRE will take care of the rest.
There are several things happening under the hood to make file uploads work:
CBWIRE makes an initial request to the server to get a temporary "signed" upload URL.
Once the URL is received, JavaScript then does the actual "upload" to the signed URL, storing the upload in a temporary directory designated by CBWIRE and returning the new temporary file's unique hash ID.
Once the file is uploaded, and the unique hash ID is generated, CBWIRE makes a final request to the server, telling it to "set" the desired data property to the upload file as an instance of FileUpload ( see below ).
Now the data property (in this case
photo
) is set to an instance ofFileUpload@cbwire
and is ready to be stored or validated at any point.
FileUpload Object
CBWIRE will automatically upload your files and set your associated data property to an instance of FileUpload@cbwire
. Here are some of the methods you can use that can get quite helpful.
Loading Indicators
You can display a loading indicator scoped to the file input during upload like so:
The "Uploading..." message will be shown as the file is uploading and then hidden when the upload is finished.
This works with the entire Loading States API.
Last updated