Note:Any Coral CSS classes and attributes not explicitly mentioned in the public documentation are private and subject to change. Their direct use is not recommended and at high risk of breaking after subsequent updates of CoralUI library. For technical details of how to use Coral safely, please refer to the CoralUI Architecture.
The FileUpload component can be used in place of a <form> tag to upload files.
Simply add the <coral-fileupload> tag where you would like to accept file uploads and use the
special [coral-fileupload-*] attributes to add functionality to elements within it.
By default, FileUpload will upload files using a POST request.
You can set the method attribute to to PUT or PATCH,
depending on your use case.
The async attribute can be used to submit the form files asynchronously. In this case, the data is
submitted via a XMLHttpRequest. By default, asynchronous upload is disabled.
The FileUpload component can be nested inside of a <form> and used as a styled file selection button
that optionally accepts drag and drop operations.
As usual, add the <coral-fileupload> tag and set the [coral-fileupload-*] attributes
on child elements to add upload functionality to them.
When using FileUpload synchronously, if you need to change the HTTP method or action URL of the request, do so on the
<form> tag itself, not the <coral-fileupload> tag.
When using FileUpload asynchronously, the action attribute is used as the upload URL.
If you would like to change the upload URL based on which button was clicked, you can do so with the
[formaction]
and
[formmethod]
attributes. This works across all browsers when using FileUpload asynchronously.
Because these attributes are part of HTML 5, it will also affect the action of the <form> when
used within a <coral-fileupload> element that is a child of a <form>
element. Note that browser support for [formaction]/[formmethod] is poor in outdated
browsers, so when FileUpload synchonrously in combination with these attributes, you must polyfill this behavior.
<coral-fileuploadaction="/files"multiple><buttoncoral-fileupload-selectis="coral-button">Browse...</button><buttonis="coral-button"variant="primary"coral-fileupload-submitformaction="/media">Upload to /media</button><buttonis="coral-button"variant="primary"coral-fileupload-submit>Upload to /files</button></coral-fileupload>
MIME types allowed for uploading (proper MIME types, wildcard '*' and file extensions are supported). To specify
more than one value, separate the values with a comma (e.g.
<input accept="audio/*,video/*,image/*" />.
The URL where the upload request should be sent. When used within a <form> tag to upload
synchronously, the action of the form is used. If an element is clicked that has a
[coral-fileupload-submit] attribute as well as a [formaction] attribute, the action of
the clicked element will be used. Set this property before calling Coral.FileUpload#upload to reset the
action set by a click.
Whether files should be uploaded asynchronously via XHR or synchronously e.g. within a
<form> tag. One option excludes the other. Setting a new async value removes all
files from the queue.
Reference to a space delimited set of ids for the HTML elements that provide a label for the formField.
Implementers should override this method to ensure that the appropriate descendant elements are labelled using the
aria-labelledby attribute. This will ensure that the component is properly identified for
accessibility purposes. It reflects the aria-labelledby attribute to the DOM.
The HTTP method to use when uploading files asynchronously. When used within a <form> tag to
upload synchronously, the method of the form is used. If an element is clicked that has a
[coral-fileupload-submit] attribute as well as a [formmethod] attribute, the method of
the clicked element will be used. Set this property before calling Coral.FileUpload#upload to reset the
method set by a click.
Whether this field is readOnly or not. Indicating that the user cannot modify the value of the control.
This is ignored for checkbox, radio or fileupload.
Non-destructively remove this element. It can be re-added by simply appending it to the document again.
It will be garbage collected if there are no more references to it.