Skip to content

Node.JS SDK Image Reference

upload (req, fileRoute, options, callback)

Method used to upload image to the specified location on disk.

Parameters:


  • req

    In Node.JS, the uploaded image is available in the request received by your application.

    Type: Request Object

  • fileRoute

    The path of the image is relative to the root of your application.

    Type: String

  • options

    This parameter is optional. It can be used to pass custom options for the image upload.

    Type: Object

  • callback

    A callback function which is called when the upload method has finished, or an error occurs. Invoked with (err, data).

    Type: Function


options parameter:

  • fieldname

    The field name from the request object.

    Type: String
    Default:
    "file"
  • validation

    A Javascript Object or a function used to validate the uploaded image. The Javascript Object specifies the allowed image extensions through allowedExts and the allowed mime types through allowedMimeTypes. The function should be invoked with: filePath, mimetype, and callback.

    Type: Object or Function
    Default:
    {
      'allowedExts': ['gif', 'jpeg', 'jpg', 'png', 'svg', 'blob'],
      'allowedMimeTypes': ['image/gif', 'image/jpeg', 'image/pjpeg', 'image/x-png', 'image/png', 'image/svg+xml']
    }
    
  • resize

    An array with custom options to scale the image. Available options are the ones from Node.JS GraphicsMagick library resize. Example:

    [200, 200, "!"]

    Type: Array
    Default:
    NULL

delete (src, callback)

Method used to delete an image from disk.

Parameters:


  • src

    The image path available in the body of the request: request.body.src.

    Type: String

  • callback

    A callback function which is called when the delete method has finished, or an error occurs. Invoked with (err, data).

    Type: Function

list (folderPath, thumbPath, callback)

Method used to list all images from disk.

Parameters:


  • folderPath

    The path of the folder from where the images are being loaded is relative to the root of your application.

    Type: String

  • thumbPath

    This parameter is optional. The path of the folder from where the image thumbs are being loaded is relative to the root of your application.

    Type: String

  • callback

    A callback function which is called when the list method has finished, or an error occurs. Invoked with (err, data).

    Type: Function

File: 2101