Options
All
  • Public
  • Public/Protected
  • All
Menu

Cloud storage APIs for uploading and processing files.

Hierarchy

  • CloudStorageInterface

Implemented by

Index

Methods

  • audioToMp3(options: { url: string }): string
  • audioToText(options: { url: string; done: any }): void
  • Audio to text Note that this feature is only available in NIM. Chat room has not yet implemented this feature.

    • Only supports the audio URL obtained by previewFile or sendFile, or the URL of the received audio message.

    Parameters

    Returns void

  • blurImage(options: { radius: number; sigma: number; url: string; done?: any }): void
  • apply Gaussian blurring

    • Only support image URLs obtained by previewing files or sending file messages, or image URLs obtained after other image operations.

    Parameters

    • options: { radius: number; sigma: number; url: string; done?: any }
      • radius: number

        Gaussian blurring radius

      • sigma: number

        Gaussian blur standard deviation, cannot be less than 0

      • url: string

        Original URL to the image stored in NOS

      • done?:function

    Returns void

  • cropImage(options: { height: number; url: string; width: number; x: number; y: number; done?: any }): void
  • Crop an image

    • Only support image URLs obtained by previewing files or sending file messages, or image URLs obtained after other image operations.
    • Capture an image with size (width*height) from coordinates (x, y). The value of (0, 0) represents the upper left corner
    • The value of width/height cannot be less than 0. If width/height is greater than the original width/height of the image, it will be replaced by the original width/height of the image.

    Parameters

    • options: { height: number; url: string; width: number; x: number; y: number; done?: any }
      • height: number

        height, must be an integer

      • url: string

        Original URL to the image stored in NOS

      • width: number

        width, must be an integer

      • x: number

        X coordinate, must be an integer

      • y: number

        Y coordinate, must be an integer

      • done?:function

    Returns void

  • deleteNosAccessToken(options: { ext?: string; url: string; userAgent?: string; done: any }): void
  • Get the authentication token of the shortened URL.

    Parameters

    • options: { ext?: string; url: string; userAgent?: string; done: any }
      • Optional ext?: string
      • url: string

        URL to the file

      • Optional userAgent?: string
      • done:function
        • Parameters

          • err: null | NIMCommonError | Error | NIMStrAnyObj
          • data: { resUrl: string; token: string }
            • resUrl: string

              Full accessible URL

            • token: string

          Returns void

    Returns void

  • getNosAccessToken(options: { ext?: string; url: string; userAgent?: string; done: any }): void
  • Get the authentication token of the shortened URL to get the file.

    • If the parameter nosScenes is set to a string starting with nim_security_ when uploading a file, you must obtain a token before downloading the file. The parameter nosScenes can be configured during initialization, or when sending and previewing a file
    • Delete CloudStorageInterface.deleteNosAccessToken the token in time after downloading the file to avoid token leakage

    Parameters

    • options: { ext?: string; url: string; userAgent?: string; done: any }
      • Optional ext?: string
      • url: string

        URL to get the file

      • Optional userAgent?: string
      • done:function
        • Parameters

          • err: null | NIMCommonError | Error | NIMStrAnyObj
          • data: { resUrl: string; token: string }
            • resUrl: string

              Full accessible URL

            • token: string

          Returns void

    Returns void

  • getNosOriginUrl(options: { safeShortUrl: string; done: any }): void
  • Shortened URL to full URL

    Parameters

    Returns void

  • interlaceImage(options: { url: string; done?: any }): void
  • interlace image

    • Only support image URLs obtained by previewing files or sending file messages, or image URLs obtained after other image operations.
    • When the network condition is poor, interlaced images appears blurry or with lower resolution and then gradually becomes clearer.

    Parameters

    • options: { url: string; done?: any }

    Returns void

  • packFileDownloadName(options: { name: string; url: string }): string
  • deprecated.

    Modify the name of the downloaded image


    If the file is stored in NetEase Yunxin's NOS, see the storage object document https://sf.163.com/help/documents/114085619316215808

    Parameters

    • options: { name: string; url: string }
      • name: string
      • url: string

    Returns string

  • Upload and preview files. Send a file message by calling the method.

    Notes

    • Select one of the four parameters fileInput, file, blob, and filePath
    • fileInput: The id of the input element of type='file'. Do not operate the file on this node until the upload is complete
    • file: Parameters of the previewFile callback
    • blob: JavaScript object of blob type
    • filePath: React Native, Mini Program and other special JS runtime environments (the temporary path obtained by chooseImage)

    Notes

    • type: image, audio, video or file. The default value is file. The information contained in the file object in the message body is different
    • image: url, name, size, ext, w, h, type
    • audio: url, name, size, ext, container, dur
    • video: url, name, size, ext, container, dur, w, h
    • file: url, name, size, ext

    Notes

    • A maximum of 100MB for the file size is allowed
    • Advanced browsers will detect the file size before uploading
    • IE8/IE9 will detect the file size after uploading

    Parameters

    Returns void

  • processImage(options: { ops: NIMStrAnyObj; url: string; done?: any }): void
  • Process an image

    This method receives a set of image operations, and processes the images in order of operations. The optional operations include:

    • Modify the image quality
    • interlace image
    • Rotate an image
    • apply Gaussian blurring
    • crop the image
    • generate a thumbnail
    • preview the file
    • send a file message

    For the parameters required for each operation, see the above methods. In addition to the parameters listed in the above methods, each operation needs to provide the operation types:

    • 'quality'
    • 'interlace'
    • 'rotate'
    • 'blur'
    • 'crop'
    • 'thumbnail'

    Code sample

    // Rotate after cropping
    var url = 'http://nim.nos.netease.com/MTAxMTAwMg==/bmltYV8xNDc5OTNfMTQ0MzE0NTgyNDI0M184YjFkYTMwMS02NjcxLTRiYjktYTUwZC04ZTVlZjZlNzZjMzA=';
    nim.processImage({
    url: url,
    ops: [
    {
    type: 'crop',
    x: 100,
    y: 0,
    width: 250,
    height: 250,
    },
    {
    type: 'thumbnail',
    mode: 'cover',
    width: 80,
    height: 80
    }
    ],
    done: processImageDone
    });
    function processImageDone(error, obj) {
    console.log('Processing the image' + (!error?'success':'failure'), error, obj);
    }

    Parameters

    • options: { ops: NIMStrAnyObj; url: string; done?: any }
      • ops: NIMStrAnyObj

        Operation sequence. Process images sequentially according to the order of operations. For the specific format, see the previous image processing interfaces

        Similar effects

        [ { type: 'crop', x: 100, y: 0, width: 250, height: 250, }, { type: 'thumbnail', mode: 'cover', width: 80, height: 80 } ]

      • url: string
      • done?:function

    Returns void

  • qualityImage(options: { quality: number; url: string; done?: any }): void
  • Modify the image quality

    • Only support image URLs obtained by previewing files or sending file messages, or image URLs obtained after other image operations.
    • The default image quality is 100. You can reduce the picture quality to save data usage for apps.

    Parameters

    • options: { quality: number; url: string; done?: any }
      • quality: number

        Image quality, integer, value range: 0-100

      • url: string

        Original URL to the image stored in NOS

      • done?:function

    Returns void

  • rotateImage(options: { angle: number; url: string; done?: any }): void
  • Rotate an image

    • Only support image URLs obtained by previewing files or sending file messages, or image URLs obtained after other image operations.

    Parameters

    • options: { angle: number; url: string; done?: any }
      • angle: number

        Rotation angle

      • url: string

        Original URL to the image stored in NOS

      • done?:function

    Returns void

  • stripImageMeta(options: { url: string; done: any }): string
  • Remove the metadata of an image

    • Only support image URLs obtained by previewing files or sending file messages, or image URLs obtained after other image operations.
    • Image without meta information will not contain EXIF information

    Parameters

    Returns string

  • thumbnailImage(options: { axis: { x: number; y: number }; height?: number; url: string; width?: number; done?: any }): void
  • Generate the thumbnails of an image

    • Only support image URLs obtained by previewing files or sending file messages, or image URLs obtained after other image operations.
    • The value of width/height limits the size of the thumbnail. - The value of width/height must be greater than or equal to 0, cannot be 0 at the same time, and must be less than 4096
    • The thumbnails generated in different modes are different, currently the following three modes are supported:
    • 'cover': The original image is scaled in proportion, one side of the thumbnail is equal to the requested size, and the other side is larger than the requested size, that is, the thumbnail can just cover the rectangle with the size of width*height
    • 'contain': The original image is proportional to the thumbnail, one side of the thumbnail is equal to the requested size, and the other side is larger than the requested size, that is, a rectangle with a size of width*height can just cover the thumbnail
    • 'crop': First get the thumbnail based on the original image proportionally so that one side is equal to the requested size and the other side is larger than the requested size, and then crop the side larger than the requested size so that the final image size is exactly equal to the requested size (Note: the crop mode does not support thumbnails to GIFs)
    • If the size of the thumbnail is larger than the size of the picture, the picture will not be enlarged by default, you can pass the parameter `enlarge= true to enlarge the picture.
    • In 'crop' mode, parameters axis.x or axis.y can be used to control the position of the last cropping step.
    • The value X and Y must be integers, the value range is 0-10. This method internally uses Math.round to format x/y.
    • If X is set to 0, the leftmost side is cropped and if X is set tos 10, the rightmost side is cropped
    • If Y is 0, it means to crop the top. If Y is 10, it means to crop the bottom.
    • The default value of x/y is 5, that is, cut the middle

    Parameters

    • options: { axis: { x: number; y: number }; height?: number; url: string; width?: number; done?: any }
      • axis: { x: number; y: number }

        Coordinates for cropping

        • x: number

          X coordinate, must be an integer

        • y: number

          Y coordinate, must be an integer

      • Optional height?: number

        Height of an thumbnail

      • url: string

        Original URL to the image stored in NOS

      • Optional width?: number

        Width of an thumbnail

      • done?:function

    Returns void