angular - 在 IONIC 3 中下载多个文件时出现错误代码 3(连接错误)
问题描述
我想从 ionic 3 的服务器下载多个文件(图像、pdf、视频和音频)。
使用离子文件传输插件:- https://ionicframework.com/docs/native/file-transfer/
我正在尝试从服务器下载大约 1k 个文件。但是当它启动时,它工作正常。但是在某些文件下载后,它会显示 FileTransferError 错误代码为 3,其余所有文件将显示相同的图像。
代码:-
// 此函数将从数据库中获取文件路径(1k)并将其传递给 fileDownloadFromServer 函数。
getDownloadFilePath() { let that = this; return new Promise((resolve, reject) => { that.database.executeSql('SELECT * FROM tableName').then((data) => { for (let i = 0, len = data.rows.length; i < len; i++) { that.fileDownloadFromServer(data.rows.item(i), data.rows.length).then((data) => { }); } }).catch(e => { console.log("here hjere"); resolve("error"); console.log(e); }) }); }
// 这个函数实际上将使用文件传输对象从服务器下载文件。
fileDownloadFromServer(fileDownloadData, fileCount) { return new Promise((resolve, reject) => { let that = this; if (this.platform.is('ios')) { this.fileLocalpath = this.file.documentsDirectory; } else if (this.platform.is('android')) { this.fileLocalpath = this.file.dataDirectory; } that.options = { headers: { "Authorization": "Basic " + that.authData } } let fileTransferObj: FileTransferObject = that.fileTransfer.create(); let tmpFilePath = fileDownloadData.globalPath; let tmpFileName = fileDownloadData.folderName; let tmpRandomNumber = Math.floor(Math.random() * 10000000000000); let tmpSourceFilePath = encodeURI(downloadFilePath + tmpFilePath + '/' + tmpFileName); let tmpTargetFilePath = that.fileLocalpath + tmpRandomNumber + '_' + tmpFileName.replace(/ /g, "_"); fileTransferObj.download(tmpSourceFilePath, tmpTargetFilePath, false, that.options).then((entry) => { console.log('download complete: ' + entry.toURL()); }, (error) => { console.log("Error for taget file = "+tmpTargetFilePath) console.log(error); }); }); }
解决方案
推荐阅读
- ios - 具有大量图像的 UITableView
- javascript - 在单个文件中导入所有 vue js 组件
- ios - ios背景白色渐变
- tableau-api - 如何从相对日期过滤器中获取天数?
- java - 寻找一种从 cloudhopper smpp 服务器返回带有错误代码的 DeliverSmResp 的方法
- excel - 如何将 Excel 连接到我的 Azure SQL 数据库,以便下载和更新数据?
- mysql - 运行“优化表表名”后表大小增加;
- swift - 调整视图大小时如何修复CoreGraphics虚线更改
- ionic-framework - 通过 Ionic 移动应用从 Azure 机器学习工作室发送数据并获取结果
- docker - Docker镜像白标