【发布时间】:2014-04-23 14:06:39
【问题描述】:
我正在为移动设备构建一个网站,它使用 angular-file-upload.min.js 从移动设备图像库上传图像。
html代码:
<div>
<div class="rating-camera-icon">
<input type="file" accept="image/*" name="file" ng-file-
select="onFileSelect($files)">
</div>
<img ng-show="fileName" ng-src="server/{{fileName}}" width="40"
style="margin-left:10px">
</div>
代码:
$scope.onFileSelect = function($files) {
for (var i = 0; i < $files.length; i++) {
var file = $files[i];
if (!file.type.match(/image.*/)) {
// this file is not an image.
};
$scope.upload = $upload.upload({
url: BASE_URL + 'upload.php',
data: {myObj: $scope.myModelObj},
file: file
}).progress(function(evt) {
// console.log('percent: ' + parseInt(100.0 * evt.loaded / evt.total));
// $scope.fileProgress = evt.loaded / evt.total * 100.0;
}).success(function(data, status, headers, config) {
// file is uploaded successfully
$scope.fileName = data;
});
}
};
移动设备上的上传速度非常慢。如何压缩文件?
【问题讨论】:
-
如果您不使用本机应用程序,则无法压缩文件,据我所知,大多数图像(如 jpg)已经被压缩,您无能为力。
-
如果您在上传之前正在寻找图像处理,这可能会有所帮助:stackoverflow.com/questions/2434458/…
标签: javascript angularjs html file-upload compression