Ionic Upload Image to Server

假装没事ソ 提交于 2019-12-12 00:17:33

问题


I need to upload captured image and album image to the server in ionic app. Is anyone know how to do that? I am just fresh in developing ionic app


回答1:


It is not really clear what you mean by uploading an image to the server with an ionic app.

A suggestion might be to convert the image to a Base64 string and send it to the server.




回答2:


i am using cordova imagepicker(pick image from camera) and upload to s3 server.

 function getImageFromGallery(cb) {
    // console.log('getImageFromGallery');
    var options = {
        maximumImagesCount: 1,
        width: 1280, //width of image 
        height: 1280, // height of image 
        quality: 80
    };
    $cordovaImagePicker.getPictures(options)
        .then(function(results) {
            console.log(results);
        }, function(error) {
            alert(error);
        });
} 
   
    function uploadImage(imageDataURI) {
        // console.log('uploadImage');
        var fileURL = imageDataURI;
        var options = new FileUploadOptions();
        options.fileKey = "image";
        options.fileName = fileURL.substr(fileURL.lastIndexOf('/') + 1);
        options.chunkedMode = true;
        options.method = 'POST';
        var params = {
            'image_type': 'food'
        };
        options.params = params;

        var ft = new FileTransfer();
        ft.upload(fileURL, encodeURI("http://xxx.in/api/upload_image"),
            viewUploadedPictures,
            function(error) {
                console.log(error);
            }, options);
        console.log('success');
    }
var viewUploadedPictures = function(response) {
    var res = response.response;
    var jres = JSON.parse(res);
    var imgUrl = jres.data.public_photo_url;
    console.log('new image url link', imgUrl);
} 

Note:- i am using REST api for image uploading "http://xxx.in/api/upload_image" * * Dependency Injection $upload* *



来源:https://stackoverflow.com/questions/33297497/ionic-upload-image-to-server

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!