javascript - 使用 cordova 文件传输附加 pdf/word 文件
问题描述
我正在使用 Cordova 文件传输插件来上传和下载 jpf/png 文件。下面是我这样做的代码。
$scope.getFileFromGallery = function () {
var options = {
maximumImagesCount: 1,
quality: 50,
destinationType: Camera.DestinationType.FILE_URI,
sourceType: Camera.PictureSourceType.PHOTOLIBRARY,
allowEdit: false,
encodingType: Camera.EncodingType.JPEG,
popoverOptions: CameraPopoverOptions,
saveToPhotoAlbum: false,
correctOrientation: true
};
$cordovaCamera.getPicture(options).then(function (imageURI) {
window.resolveLocalFileSystemURL(imageURI, function (fileEntry) {
fileEntry.file(function (file) {
$scope.uploadFile(file, imageURI);
}, function () {
$scope.showToastMsg("Error Occurred");
});
});
}, function (error) {
// error
});
};
$scope.uploadFile = function (file, imageURI) {
LoaderFactory.showLoader();
var uri = encodeURI(baseURL + "api/files/upload");
var options = new FileUploadOptions();
options.fileKey = "file";
options.fileName = file.name;
options.mimeType = file.type;
var headers = { 'Authorization': getStorage('accessToken') };
options.headers = headers;
var ft = new FileTransfer();
ft.onprogress = function (progressEvent) {
if (progressEvent.lengthComputable) {
$scope.percentage = Math.floor(progressEvent.loaded / progressEvent.total * 100);
$scope.showToastMsg("Uploading Progress " + $scope.percentage + "%");
if (myTimeOut)
clearTimeout(myTimeOut);
var myTimeOut = setTimeout(function () {
LoaderFactory.hideLoader();
}, 5000);
} else {
}
};
ft.upload(file.localURL, uri, win, fail, options);
$scope.imageURL = '';
$scope.imageURL = {
name: file.name,
URL: imageURI
};
};
但我没有得到任何线索来更改这段代码以选择和附加 pdf 文件或 word 文件。我也试过https://www.tutorialspoint.com/cordova/cordova_file_transfer.htm。关于如何修改上述内容以选择和上传 pdf 和 word 文件的任何线索。我在 Ionic1 中这样做。
解决方案
推荐阅读
- spotfire - Spotfire:编辑交叉表的标题
- php - 定位多余的空格,但保留新行
- sql - oracle sql中的条件不能正常工作,因为有时为空
- sql-server - 如何在 Microsoft SQL Server 中对临时表中的所有列求和,就像 Pandas 中的值计数一样
- excel - 如何选择所有完整的单元格并复制到其他文档 vba
- c# - 来自 ML.NET 的正弦预测并没有真正起作用
- excel - 计算excel单元格中每个单词的字符数
- redis - Redis 流水线何时变得更高效?
- c# - 开发工具包 AWS 和 Lambda 函数
- php - 解密 CakePHP 1.2 数据