downloadFile

Requires:
BaseKit≥2.3.2@ray-js/ray≥0.3.23
Platforms:
iOSAndroid
import { downloadFile } from '@ray-js/ray';

// Promise usage
try {
  const res = await downloadFile({ ...params });
  console.log(res);
} catch (err) {
  console.log(err.errorMsg);
}

Method signature
downloadFile(params: )
Minimum SDK versions
iOSThingSmartBaseKitBizBundle
≥ 5.2.1
Androidcom.thingclips.smart:thingsmart-bizbundle-basekit
≥ 5.2.0

Description

Download a file resource to local storage. The client directly initiates an HTTPS GET request and returns the file’s local temporary path (local path). The maximum file size per download is 200 MB. Read the related notes before use. Note: Specify an appropriate Content-Type header in the server response to ensure the client handles the file type correctly.

Parameters

PropertyTypeRequiredDescriptionMinimum SDK versions
urlstringYesURL of the resource to download—
headerRecord<string, string>NoHTTP request headers; Referer cannot be set—
timeoutnumberNoTimeout in milliseconds—
filePathstringNoPath to store the downloaded file (local path)—
complete() => voidNoCompletion callback (executed on both success and failure)—
success(params: Object) => voidNoCallback on successful API call—
fail(params: Object) => voidNoFailure callback—
success callback parameters
PropertyTypeDescriptionBaseKit SinceMinimum SDK versions
tempFilePathstringTemporary file path (local path). Returned when filePath is not provided; the downloaded file is stored in a temporary filev3.2.6—
filePathstringUser file path (local path). Returned when filePath is provided; identical to the given filePathv3.2.6—
statusCodenumberHTTP status code returned by the developer serverv3.2.6—
Debug information during the requestv3.2.6—
fail callback parameters
PropertyTypeDescription
errorMsgstringError message
errorCodestring | numberError code
Error extension

Return Value

Type: DownloadTask
DownloadTask
PropertyTypeDescriptionBaseKit SinceMinimum SDK versions
abortfunctionAbort the download taskv2.0.1—
onHeadersReceivedfunctionListen for HTTP Response Header events. Fires before the request completion eventv2.0.1—
offHeadersReceivedfunctionStop listening for HTTP Response Header eventsv2.0.1—
onProgressUpdatefunctionListen for download progress change eventsv2.0.1—
offProgressUpdatefunctionStop listening for download progress change eventsv2.0.1—

Examples

import { downloadFile } from '@ray-js/ray'

downloadFile({
  url: "https://airtake-public-data-1254153901.cos.ap-shanghai.myqcloud.com/ttttestfile/test_video.mp4",
  success: data => {
    console.log(data);
  },
  fail: error => {
    console.error(error);
  },
});