loadVideoWithUrl(url: string) {
this.dialogId=DialogHelper.showLoadingDialog()
// 使用request下载图片
http.createHttp().request(url,
{
method: http.RequestMethod.GET,
connectTimeout: 60000,
readTimeout: 60000,
expectDataType: 2,
},
async (error: BusinessError, data: http.HttpResponse) => {
DialogHelper.closeDialog(this.dialogId)
if (error) {
console.error(`http reqeust failed with. Code: ${error.code}, message: ${error.message}`);
} else {
if (HttpConstants.SUCCESS_CODE === data.responseCode) {
let videoBuffer: ArrayBuffer = data.result as ArrayBuffer;
try {
//
let uris = url.split('/')//-------http://192.168.1.243/2025/03/05/b037b1a863e9444589b21a0482d3f1e0.pdf
let atten=uris[uris.length-1].split('.')[uris[uris.length-1].split('.').length-1]//文件后缀名
let name=uris[uris.length-1].split('.')[0]//文件名 不带后缀民
let uri: string = '';
// 请确保 getContext(this) 返回结果为UIAbilityContext
let context = getContext(this) as common.Context;
const documentViewPicker = new picker.DocumentViewPicker(context);
const documentSaveOptions = new picker.DocumentSaveOptions();
documentSaveOptions.pickerMode = picker.DocumentPickerMode.DOWNLOAD;
documentViewPicker.save(documentSaveOptions ).then((documentSaveResult: Array<string>) => {
uri = documentSaveResult[0];
console.info('documentViewPicker.save succeed and uri is:' + uri);
const testFilePath = new fileUri.FileUri(uri + '/【虎翅云】'+(name)+'-附件.'+atten).path;
const file = fs.openSync(testFilePath, fs.OpenMode.CREATE | fs.OpenMode.READ_WRITE);
fs.writeSync(file.fd, videoBuffer);
fs.closeSync(file.fd);
ToastUtil.showToast('已保存至手机下载目录下');
})
} catch (error) {
console.error("error is " + JSON.stringify(error))
}
} else {
console.error("error occurred when image downloaded!")
}
}
})
}