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 asurlFiles
andurlFileManager
. -
filesOrLinks
:(File|string)[]A list of files or links that you wish to upload programmatically. You can mix
Files
objects andstring
URLs in this array, and Flmngr will return them in the same order within theonFinish
callback. -
This parameter sets the directory into which you want to upload the files.
The path of this directory is relative to the
urlFiles
(ordirFiles
option on the server).If you have already set it before, it will override the value of
defaultUploadDir
by callingFlmngr.load({params})
separately.The default is
"/"
(the root directory of your storage) ifdefaultUploadDir
was not set.Optional -
Use this parameter to switch between file overwriting files and automatically renaming them during the upload process.
Default is
"ASK"
. Optional-
"ASK"
Show the dialog with available options: Auto Rename, Overwrite, or Set Name for uploaded files that conflict with existing ones.
-
"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
filesOrLinks
parameter.Each file will have a
url
parameter that you can use. There will be additional information available, especially for image files.url
represents the full absolute URL (based on theurlFiles
you passed) that you can use everywhere.name
indicates the name of the file in the file system, while thesize
specifies the number of bytes files takes on disk. Thetimestamp
comes in millisec from Unix epoch,width
andheight
represent the dimensions of the image in pixels, and theblurHash
is a super small preview of an image.Default is
null
Optional -
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
error
parameter containing a human-readable description of the problem.Default is
null
Optional