Upload files or images to server
Flmngr.upload
Uploads single or multiple files to the server without showing any UI elements.
Specify the files in the filesOrLinks parameter and the target folder in the dirUploads parameter. You can switch between overwrite/autorename mode using the mode parameter.
It's useful to combine this method with either Flmngr.selectFiles({params}) or Flmngr.selectUrls({params}) methods to allow users to specify files before uploading.
What's next: you can use your image through the returned URL. Optionally, if you need to create additional image formats (i. e. previews) for the uploaded files, you can call the Flmngr.createImageFormats({params}) method. But if you only need to regenerate already existing previews, you can skip this step. The Flmngr.upload({params}) method automatically handles this for all the passed imageFormats.
Code samples:
Parameters
-
...common parameters:{ any parameters ofFlmngr.load()method }All parameters that you can pass to the
Flmngr.load({params})method are also available here. So you can override some values (exceptapiKey) or pass parameters that were missing in theFlmngr.load()call but are required for this method, such asurlFilesandurlFileManager. -
filesOrLinks:(File|string)[]A list of files or links that you wish to upload programmatically. You can mix
Filesobjects andstringURLs in this array, and Flmngr will return them in the same order within theonFinishcallback. -
This parameter sets the directory into which you want to upload the files.
The path of this directory is relative to the
urlFiles(ordirFilesoption on the server).If you have already set it before, it will override the value of
defaultUploadDirby callingFlmngr.load({params})separately.Optional Default is
"/"(the root directory of your storage) ifdefaultUploadDirwas not set. -
Use this parameter to switch between file overwriting files and automatically renaming them during the upload process.
Optional Default is
"AUTORENAME"<!--"ASK"-->-
"OVERWRITE"All uploaded files will overwrite existing ones on your server if they exist in the same folder with the same name.
-
"AUTORENAME"The file manager will automatically rename the newly uploaded files that conflict with existing ones. The name of renamed files will be like
"image_1.png".
-
-
onFinish:( files: { url: string, name: string, size: number, timestamp: number, blurHash: string, width: number, height: number, }[] ) => void;A callback to handle the successful finish of file uploading. This callback will receive a list of files ordered as you specified in the
filesOrLinksparameter.Each file will have a
urlparameter that you can use. There will be additional information available, especially for image files.urlrepresents the full absolute URL (based on theurlFilesyou passed) that you can use everywhere.nameindicates the name of the file in the file system, while thesizespecifies the number of bytes files takes on disk. Thetimestampcomes in millisec from Unix epoch,widthandheightrepresent the dimensions of the image in pixels, and theblurHashis a super small preview of an image.Optional Default is
null -
onFail:(error: string) => void;A callback to handle any errors that occur during the uploading process. If the upload finishes with a negative result, this callback is triggered with an
errorparameter containing a human-readable description of the problem.Optional Default is
null