Skip to main content
Upload a file to a remote server.

Parameters

PropertyTypeRequiredDescription
urlStringYesUpload endpoint URL
filePathStringYesLocal file path
fileNameStringYesFile name
fileTypeStringYesFile type: image, video, audio
formDataObjectNoAdditional form data
headerObjectNoRequest headers
successFunctionNoCallback on success
failFunctionNoCallback on failure
completeFunctionNoCallback that always executes

Success Callback

PropertyTypeDescription
dataStringServer response
statusCodeNumberHTTP status code

Code Example

my.uploadFile({
  url: 'https://api.example.com/upload',
  filePath: localPath,
  fileName: 'image',
  fileType: 'image',
  formData: { userId: '123' },
  success: (res) => {
    console.log('Uploaded:', res.data);
  }
});