【问题标题】:Ionic Upload Image to Server离子上传图像到服务器
【发布时间】:2015-10-23 08:01:13
【问题描述】:

我需要将捕获的图像和相册图像上传到 ionic 应用程序中的服务器。 有人知道该怎么做吗? 我刚刚开发 ionic 应用程序

【问题讨论】:

标签: ionic image-uploading image-capture


【解决方案1】:

使用离子应用程序将图像上传到服务器并不是很清楚。

建议可能是将图像转换为 Base64 字符串并将其发送到服务器。

【讨论】:

  • 我传给服务器的图片是base64,但是上传失败
【解决方案2】:

我正在使用cordova imagepicker(从相机中选择图像)并上传到s3服务器。

 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);
} 

注意:- 我正在使用 REST api 上传图片“http://xxx.in/api/upload_image” * * 依赖注入 $upload* *

【讨论】:

    猜你喜欢
    • 2019-03-25
    • 2022-09-26
    • 2017-06-22
    • 2013-12-17
    • 2014-03-21
    • 2017-05-31
    • 2013-11-02
    • 2014-03-24
    • 1970-01-01
    相关资源
    最近更新 更多