简体   繁体   English

如何使用Cordova和angularjs在混合移动应用程序中上传pdf文件?

[英]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.

相关问题 使用HTTPS / SSL密码安全性的混合Cordova移动应用程序 - hybrid cordova mobile app using HTTPS/SSL password security 如何在Cordova混合移动应用程序中集成NetScalar登录? - How to integrate NetScalar login in cordova hybrid mobile app? 如何使用Cordova处理混合移动应用程序的后退按钮功能 - How to handle the back button functionality for Hybrid mobile application using cordova Angularjs移动应用程序的pdf文档打开问题。 与科尔多瓦建立 - pdf document opening issue with angularjs mobile app. with cordova build XDK中的Hybrid App-如何在同一上传中上传表单数据和文件 - Hybrid App in XDK - how to upload Form data and File in same upload 即使在混合Ionic Cordova移动应用程序(基于AngularJS的项目)中杀死应用程序后,本地存储也可以保留值吗? - Can Local Storage retain values even after app kill in Hybrid Ionic Cordova Mobile App (AngularJS based project)? 使用Cordova Hybrid应用程序将文件复制到路径 - Copy file to a path with Cordova Hybrid app 有没有办法使用Cordova / Hybrid App为平板电脑阅读3D Pdf? - Is there any Way to Read 3D Pdf using Cordova/Hybrid App for tablets? 如何在混合应用程序中调试onDeviceReady — Cordova - How to debug onDeviceReady in a hybrid app — cordova 使用Cordova应用程序上传文件在远程服务器上不起作用 - File upload using cordova app not working on remote server
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM