【发布时间】:2015-10-23 08:01:13
【问题描述】:
我需要将捕获的图像和相册图像上传到 ionic 应用程序中的服务器。 有人知道该怎么做吗? 我刚刚开发 ionic 应用程序
【问题讨论】:
-
你可以试试github.com/danialfarid/ng-file-upload,对我来说效果很好
标签: ionic image-uploading image-capture
我需要将捕获的图像和相册图像上传到 ionic 应用程序中的服务器。 有人知道该怎么做吗? 我刚刚开发 ionic 应用程序
【问题讨论】:
标签: ionic image-uploading image-capture
使用离子应用程序将图像上传到服务器并不是很清楚。
建议可能是将图像转换为 Base64 字符串并将其发送到服务器。
【讨论】:
我正在使用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* *
【讨论】: