async demo() {
try {
let mContext = getContext(this) as common.Context;
let filesDir = mContext.distributedFilesDir;
let filePath: string = filesDir + '/' + systemDateTime.getTime() + '.png';
console.log('the pick pickerResult is: '+filePath);
let pickerProfile: cameraPicker.PickerProfile = {
cameraPosition: camera.CameraPosition.CAMERA_POSITION_BACK,
videoDuration: 5,
saveUri: filePath
};
let pickerResult: cameraPicker.PickerResult = await cameraPicker.pick(mContext,
[cameraPicker.PickerMediaType.PHOTO, cameraPicker.PickerMediaType.VIDEO], pickerProfile);
console.log("the pick pickerResult is:" + JSON.stringify(pickerResult));
console.log("the pick pickerResult is:" + JSON.stringify(pickerResult.resultUri));
let uri = fileUri.getUriFromPath(pickerResult.resultUri);
console.log("the pick pickerResult is:" + uri);
this.checkPictureList = [{ uri: uri }];
this.sendImage()
} catch (error) {
let err = error as BusinessError;
console.error(`the pick call failed. error code: ${err.code}`+err.message);
}
}
保存到entry同级的files下的chat文件夹下,文件路径写死即可,chat为自建文件夹,以保存到files为例: