salla-file-upload

A file uploader (drag and drop, browse, optional paste) built on FilePond that uploads to a URL you give it and keeps the result in a native form field.

A file uploader (drag and drop, browse, optional paste) built on FilePond that uploads to a URL you give it and keeps the result in a native form field. Use it for avatar upload (profile-image), attaching a file or image to a cart item (cart-item-id), product option file fields, or any form that needs an upload. Set allow-multiple with max-files-count for several files, and enable-gallery for a thumbnail strip with image and video limits. Any content inside the element is used as the idle drop-area label (unless label-idle is set); put a <span class="filepond--label-action"> around the "browse" text. Upload errors show as notifications. Place it inside a <form>: the uploaded file URL is written to a hidden input named like the file input, and a change event bubbles from it.

Use it

In HTML or JSX, use the tag <salla-file-upload> with the Attribute names below. In React, the wrapper takes the Property names (camelCase).

import { SallaFileUpload } from '@salla.sa/twilight-components-react/file-upload';

Client-only. On the server this wrapper renders a placeholder (a skeleton, or nothing), and the real component mounts in the browser. Do not rely on it for content that search engines must see.

Try it

web-components/salla-file-upload

Example

import { SallaFileUpload } from '@salla.sa/twilight-components-react/file-upload';

export function Example() {
  return (
    <form>
      <SallaFileUpload
        name="attachment"
        url="/api/upload"
        instantUpload
        accept="image/png, image/jpeg"
        maxFileSize="2MB"
        required />
    </form>
  );
}

Properties

PropertyAttributeDescriptionTypeDefault
acceptacceptAccepted file types as a comma separated list of MIME types, for example "image/png, image/jpeg". Defaults to PNG, JPEG and GIF images.string"image/png, image/jpeg, image/jpg, image/gif"
allowBrowseallow-browseEnable or disable file browserbooleantrue
allowDropallow-dropEnable or disable drag n' dropbooleantrue
allowImagePreviewallow-image-previewEnable or disable preview modebooleantrue
allowMultipleallow-multipleEnable or disable adding multiple filesboolean
allowPasteallow-pasteEnable or disable pasting of files. Pasting files is not supported on all browesrs.boolean
allowProcessallow-processEnable or disable the process buttonboolean
allowRemoveallow-removeWhen set to false the remove button is hidden and disabledbooleantrue
allowReorderallow-reorderAllow users to reorder files with drag and drop interaction. Note that this only works in single column mode. It also only works on browsers that support pointer events.boolean
allowReplaceallow-replaceAllow drop to replace a file, only works when allowMultiple is falsebooleantrue
allowRevertallow-revertEnable or disable the revert processing buttonbooleantrue
cartItemIdcart-item-idThe id of a cart item. When set and url is empty, the upload goes to the cart image-upload endpoint and instant-upload is turned on. The id is also sent with the upload as cart_item_id. Used to attach a file to a cart item.string
checkValiditycheck-validitySet to true to enable custom validity messages. FilePond will throw an error when a parent form is submitted and it contains invalid files.boolean
chunkForcechunk-forceForce chunks even for files smaller than the set chunkSizeboolean
chunkRetryDelayschunk-retry-delaysAmount of times, and delayes, between retried uploading of a chunknumber[][500, 1000, 3000]
chunkSizechunk-sizeThe size of a chunk in bytesnumber5000000
chunkUploadschunk-uploadsEnable chunked uploads, when enabled will automatically cut up files in chunkSize chunks before upload.boolean
creditscreditsShow credits at the bottom of the upload element. Structure is like [{label,url}] Deprecated: Not read by the component, so it has no effect. It will be removed in the next major version.boolean
disableddisabledDisables the uploader so no files can be added.boolean
dropOnElementdrop-on-elementRequire drop on the FilePond element itself to catch the file.booleantrue
dropOnPagedrop-on-pageFilePond will catch all files dropped on the webpageboolean
dropValidationdrop-validationWhen enabled, files are validated before they are dropped. A file is not added when it's invalid.boolean
enableGalleryenable-galleryEnable the custom gallery preview instead of FilePond thumbnails.booleanfalse
fileIdfile-idIf current file has id, pass it here, to be passed back in the removed event Deprecated: Not read by the component, so it has no effect. It will be removed in the next major version.number
filePosterHeightfile-poster-heightFixed file poster height in pixels, overrides min and max preview height.numbernull
filesfilesExisting uploaded files, as a JSON string [{"url":"...","id":123}]. They are shown on load, and id is passed back in the removed event. Takes precedence over value when both are set.string
forceRevertforce-revertSet to true to require the file to be successfully reverted before continuing.boolean
formDataform-dataExtra fields for the upload request as a JSON string of name and value pairs, for example '{"folder":"avatars"}'. Entries with empty values are skipped. Not applied with allow-multiple.string"{}"
heightheightThe original height of the uploader as a CSS value (for example "150px"). It is applied again to the uploader about one second after a file is removed.string
iconProcessicon-processThe icon used for process actionsstring'<svg>...</svg>'
iconRemoveicon-removeThe icon used for remove actionsstring'<svg>...</svg>'
iconRetryicon-retryThe icon used for retry actionsstring'<svg>...</svg>'
iconUndoicon-undoThe icon used for undo actionsstring'<svg>...</svg>'
ignoredFilesignored-filesIgnored file names when handling dropped directories. Dropping directories is not supported on all browsers.any[]['.ds_store', 'thumbs.db', 'desktop.ini']
imagePreviewHeightimage-preview-heightFixed image preview height in pixels, overrides min and max preview height. Also sets the gallery thumbnail size when enable-gallery is on (default: 75).numbernull
instantUploadinstant-uploadImmediately upload new files to the serverboolean
itemInsertIntervalitem-insert-intervalThe interval to use before showing each item being added to the listnumber75
itemInsertLocationitem-insert-locationSet to 'after' to add files to end of list (when dropped at the top of the list or added using browse or paste), set to 'before' to add files at start of list. Set to a compare function to automatically sort items when added"after" | "before" | ((a: FilePondFile, b: FilePondFile) => number)'after'
labelDecimalSeparatorlabel-decimal-separatorThe decimal separator used to render numbers. By default this is determined automatically.stringundefined
labelIdlelabel-idleDefault label shown to indicate this is a drop area. FilePond will automatically bind browse file events to the element with CSS class .filepond--label-actionstring
labelThousandsSeparatorlabel-thousands-separatorThe thousdands separator used to render numbers. By default this is determined automatically.stringundefined
maxFileSizemax-file-sizeThe maximum size of a file, as a number followed by MB or KB, for instance 2MB or 750KB. If the store has an upload size setting, that setting is used instead for the limit.'${number}KB}' | '${number}MB'
maxFilesCountmax-files-countThe maximum number of files that can be added (a count). Ignored when max-images-count or max-videos-count is set.number1
maxImagesCountmax-images-countPrimary: maximum number of image files (split count mode). When set with or without maxVideosCount, maxFilesCount is ignored for count limits.number
maxParallelUploadsmax-parallel-uploadsThe maximum number of files uploaded at the same time (a count).number3
maxVideoDurationmax-video-durationMaximum video duration in seconds. Longer videos are rejected with an error notification.number
maxVideoFileSizemax-video-file-sizeMaximum size for video files only, e.g. 50MB or 750KB'${number}KB' | '${number}MB'
maxVideosCountmax-videos-countPrimary: maximum number of video files (split count mode). When set with or without maxImagesCount, maxFilesCount is ignored for count limits.number
methodmethodThe submit request method.string'POST'
namenameThe name of the file input in the native form. Defaults to file, or avatar with profile-image.string
payloadNamepayload-nameThe field name used for the file in the upload request when it must differ from name. Falls back to name. Not applied with allow-multiple, where files are sent as files[].string
payloadParamspayload-paramsExtra fields to send with the upload request, as an object of name and value pairs (set it as a JS property). Not sent with allow-multiple.{ [x: string]: unknown; }{}
profileImageprofile-imageMakes this a profile image uploader with a preview and a circular shape. When url is empty it uploads to the profile update endpoint with instant-upload on, and name defaults to avatar unless you set the name attribute.booleanfalse
requiredrequiredMakes the field required: the form cannot be submitted natively until a file has been uploaded.boolean
storeAsFilestore-as-fileTells FilePond to store files in hidden file input elements so they can be posted along with normal form post. This only works if the browser supports the DataTransfer constructor (https://caniuse.com/mdn-api_datatransfer_datatransfer), this is the case on Firefox, Chrome, Chromium powered browsers and Safari version 14.1 and higher.boolean
typetypeA value sent to the server as the type field of the upload request. Only sent when allow-multiple is on.string
urlurlThe URL the file is uploaded to. The response is expected to be JSON with the file URL in data (data.url, data.filePath, or a string; an array when uploading several files). If empty, it is set automatically when cart-item-id or profile-image is used.string
valuevalueThe current uploaded file. Set it to the file URL (a comma separated list of URLs for several files) to show an existing file. After an upload it becomes an object { id, url } for the last uploaded file. With profile-image it starts as the current user's avatar.any

Events

Listen with addEventListener, or the on prop of the React wrapper (for example onModalBack).

EventDescriptionDetail
addedFired when a file is added to the uploader. event.detail is { error, file }: error is null on success, and file is the FilePond file item (with filename, fileSize, fileType and file).{ error: FilePondErrorDescription; file: FilePondFile; }
galleryUpdatedFired when the gallery preview list changes (after an upload or a removal). Only used with enable-gallery. event.detail is { count, imageCount, videoCount, uploading }: the number of files (and of images and videos) and whether an upload is in progress.{ count: number; imageCount?: number; videoCount?: number; uploading?: boolean; }
invalidInputFired when the form validates and the field is required but has no file. event.detail is the native invalid event.any
removedFired when a file is removed. event.detail is the id of the removed file when known (the id from files or the upload), otherwise its URL, server id or FilePond file id.number | string
uploadedFired after a file has been uploaded and the server returned its link. event.detail is the current value: an object { id, url } for the uploaded file.string

Methods

Call these on the element or a React ref.

setOption(key: string, value: string | number) => Promise<void>

Sets one FilePond option on the underlying FilePond instance, for example setOption('maxFiles', 3). Call it after the component has loaded.

ParameterTypeDescription
keystringThe FilePond option name.
valuestring | numberThe new value for the option.

Renders: <salla-loading>, <salla-attachment-view>.

Used inside: <salla-custom-fields>, <salla-gifting>, <salla-product-options>, <salla-rating-modal>, <salla-rating-modal-v2>.

On this page