将图像上传到服务器angularjs [英] Upload image to server angularjs

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

问题描述

我需要将从移动设备上拍摄的图像上传到我的服务器。我发现了角度上传库,可供参考。我需要做的是转换图像库64,通过邮件发送到我的服务器,因为服务器是我将与她合作的地方。另一方面,从我的服务器发送并从应用程序中运行它。

I need to upload an image taken from my mobile device to my server. I found the angular-upload library to which makes reference. I need to do is to transform the image base 64, send it by post to my server because the server is where I will work with her. And the other, send from my server and work it from the application to run.

var server = URL_BASE+'addView/';

var trustAllHosts = true;

var ftOptions = new FileUploadOptions();
ftOptions.fileKey = 'file';
ftOptions.fileName = $scope.imagen.substr($scope.imagen.lastIndexOf('/') + 1);
ftOptions.mimeType = 'image/jpeg';
ftOptions.httpMethod = 'POST';

console.log(ftOptions);

$cordovaFileTransfer.upload(encodeURI(server), $scope.imagen, ftOptions, trustAllHosts)
.then(function(result) {
  console.log(result)
}, function(err) {
  // Error
  console.log(err);
}, function (progress) {

});


推荐答案

离子文件传输

我个人正在使用 Cordova上传文件传输从服务器下载内容。

I'm personally using Cordova file transfer for upload & download content from a server.

Base64编码

不知道在哪里是您的图像存储以及如何检索它,但是,您指定图像是base64编码到HTML文件分隔符
OR
您使用画布转换图像
查看该帖子更多信息: https://stackoverflow.com/a/20285053/3687474

Don't know where is your image stored and how you retrieve it, but, either you specify that the image is base64 encode into the HTML file delimiter OR You transform your image using a canvas See that post for more info : https://stackoverflow.com/a/20285053/3687474

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

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