这是我尝试的方式
await this.base64.encodeFile(uri).then((base64File: string) => {
console.log(base64File);
base64_data = base64File
alert(JSON.stringify(base64_data));
console.log(base64_data);
}, (err) => {
console.log(err);
alert(JSON.stringify(err));
});
this.db.putAttachment(att_id,att_name,base64_data, att_file_type).then(function (result) {
console.log(result);
alert(JSON.stringify(result));
}).catch(function (err) {
// ouch, an error
console.log(err);
alert(JSON.stringify(err));
});
它适用于图像文件,但对于pdf文件返回“”
responseType: 'arraybuffer'
axios.get(url, {
progress: false, responseType: 'arraybuffer',
onDownloadProgress: (progressEvent) => {
precent = (100 * progressEvent.loaded / progressEvent.total)
console.log(precent)
}
})
.then(resp => {
//get db
let db = $db.dbModel
//set attach
db.get(doc._id).then((doc) => {
db.putAttachment(doc._id, 'index.mp4', doc._rev, new Blob([new Uint8Array(resp.data)], {type: 'video/mp4'}), 'video/mp4')
.then(res => {
// console.log('success store file')
})
})
})
https://github.com/mohammadnazari110/pwa_offline_video_download