Upload files or images to server

Flmngr.upload

( { params } )

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 of Flmngr.load() method }

    All parameters that you can pass to the Flmngr.load({params}) method are also available here. So you can override some values (except apiKey) or pass parameters that were missing in the Flmngr.load() call but are required for this method, such as urlFiles and urlFileManager.

  • :
    (File|string)[]

    A list of files or links that you wish to upload programmatically. You can mix Files objects and string URLs in this array, and Flmngr will return them in the same order within the onFinish callback.

  • dirUploads

    :
    string

    This parameter sets the directory into which you want to upload the files.

    The path of this directory is relative to the urlFiles (or dirFiles option on the server).

    If you have already set it before, it will override the value of defaultUploadDir by calling Flmngr.load({params}) separately.

    The default is "/" (the root directory of your storage) if defaultUploadDir was not set.Optional

  • mode

    :
    string

    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 the urlFiles you passed) that you can use everywhere. name indicates the name of the file in the file system, while the size specifies the number of bytes files takes on disk. The timestamp comes in millisec from Unix epoch, width and height represent the dimensions of the image in pixels, and the blurHash 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