my.uploadFile

Upload the local resource to the server.

Sample Code

copy
my.uploadFile({
  url: 'Please use your own server address',
  fileType: 'image',
  fileName: 'file',
  filePath: '...',
  success: (res) => {
    my.alert({
      content: 'Upload success'
    });
  },
});

Parameters

PropertyType

Required

Description
urlStringYesAddress of the developer server.
filePathStringYesLocal locator of the file resource to be uploaded.
fileNameString YesFilename, also the corresponding key. The developer uses this key at the server side to get the file binary contents.
fileTypeStringYes

The file type of the uploaded file.

Note: This parameter is only used for backward compatibility with older super app versions. If you have previously set a value for this parameter, no changes are necessary. If not, you can set the value to image for any file type.

headerObjectNo

The HTTP request header. You can specify this parameter using any common headers.

Note: By default, the Content-Type request header is set to multipart/form-data. Do not change this value, otherwise your request might fail.

formDataObjectNoOther additional form data in the HTTP request.

timeout

Number

No

The timeout period of your request in milliseconds. The default value is 60000.

hideLoading

Boolean

No

Whether to hide a loading icon during the uploading process. Valid values are:

  • true: Hide a loading icon.
  • false: Show a loading icon.

If not specified, the value defaults to false.

successFunctionNoCallback function upon call success.
failFunctionNoCallback function upon call failure.
completeFunctionNoCallback function upon call completion (to be executed upon either call success or failure).

Success Callback Function

The incoming parameter is of the Object type with the following attributes:

PropertyTypeDescription
dataStringData returned from the server.
statusCodeStringHTTP status code.
headerObjectHeader returned from the server.

Error Code

ErrorDescription
11File nonexistent.
12File uploading failed.
13No right.