离子上传图像到服务器 [英] Ionic Upload Image to Server

查看:149
本文介绍了离子上传图像到服务器的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

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

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

推荐答案

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

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

注意: - 我使用REST api进行图像上传 http://xxx.in/api/upload_image
* *依赖注入$ upload * *

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

这篇关于离子上传图像到服务器的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆