[英]How to upload pdf file in hybrid mobile app using cordova and angularjs?
I am working an app in the phonegap android in which i want to upload a file (image and pdf) to the server. 我正在phonegap android中使用一个应用程序,我想在其中将文件(图像和pdf)上传到服务器。 What i want is when an user will click on the upload button an option dialog will open from where the user will select a file to be uploaded and then when user selects the image/pdf file the file will be uploaded.
我想要的是,当用户单击上载按钮时,将打开一个选项对话框,从中可以选择要上载的文件,然后在用户选择图像/ pdf文件时上载该文件。 Image upload is working fine using below code:
使用以下代码,图像上传工作正常:
var options = {
destinationType: Camera.DestinationType.FILE_URI,
sourceType: Camera.PictureSourceType.PHOTOLIBRARY,
quality : 50
};
$cordovaCamera.getPicture(options).then(function(file) {
//success
}, function(error) {
//error
});
Am using ngcordova camera plugin: http://ngcordova.com/docs/plugins/camera/
Can anyone tell me how to upload pdf using this plugin? 谁能告诉我如何使用此插件上传pdf? If pdf upload is possible with any other plugin please share.
如果可以使用其他任何插件上传pdf文件,请分享。 Any help is appreciated.
任何帮助表示赞赏。
Thanks in advance. 提前致谢。
You can use ngcordova's
$cordovaFileTransfer , which you can use by adding the relating cordova plugin: 您可以使用
ngcordova's
$ cordovaFileTransfer ,可以通过添加相关的cordova插件来使用它:
cordova plugin add cordova-plugin-file-transfer
Example code taken from the docs : 来自docs的示例代码:
module.controller('MyCtrl', function($scope, $cordovaFileTransfer) {
var server = "http://yourserver.net/path/to/upload";
var target = cordova.file.documentsDirectory + "test.pdf";
var options = {};
document.addEventListener('deviceready', function () {
$cordovaFileTransfer.upload(server, target, options)
.then(function(result) {
// Success!
}, function(err) {
// Error
}, function (progress) {
// constant progress updates
});
}, false);
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.