my.chooseFileFromDisk

You can choose a file to upload. You can also view the details of the file or delete the file you have added.

Sample code

copy
<!--.axml-->
<view class="page">
  <view class="page-description">file API</view>
    <view class="page-section-demo">
      <button class="page-body-button" onTap="chooseFileFromDisk">Choose file from disk</button>
    </view>
  </view>
</view>
copy
// .js
Page({
  chooseFileFromDisk(){
    my.chooseFileFromDisk({
      success: (res) => {
        my.alert({
          content: JSON.stringify(res),
        });
      },
      fail: (res) => {
        my.alert({
          content: JSON.stringify(res),
        });
      }
  	});
  },
});

Parameters

Property

Type

Description

Required

success

Function

The callback function for a successful API call.

NO

fail

Function

The callback function for a failed API call.

NO

complete

Function

The callback function used when the API call is completed. This function is always executed no matter the call succeeds or fails.

NO

Success callback function

Property

Type

Description

apFilePath

string

The temporary local file path.

Failure callback function

Property

Type

Description

error

number

Error code.

errorMessage

string

Error message.

Error codes

Error code

Error message

Remark

4

The JSAPI call is denied.

The mini program that is developed by the merchant/ISV has no right to call the JSAPI.

12

Errors occur when copying the file.

15

The user cancels the file selection.

16

The user denies the permission to read the storage.

Android Only.

17

No permission to read the storage.Android Only.

18

Choosing large file is not supported.

Note:

The following list describes the difference between the error code 16 and 17:

  • 16: The user denies the permission to read the storage for the current request.
  • 17: The user denied the permission last time and chose to never asking the permission again. In this case, the dialog box for the permission cannot pop up. The error code of 17 is returned directly. The mini program developer requires to call the showAuthGuide to guide the user to grant the related permission.

File size limit

If you choose a file that is too large, the mini program or the wallet app cannot run properly. For this reason, the file size is limited to 50MB. When the file size exceeds 50MB, the error code of 18 is returned and the corresponding error message is displayed.