Tôi đang bẻ một trang web cho thiết bị di động, sử dụng angular-file-upload.min.js để tải lên hình ảnh từ thư viện hình ảnh trên thiết bị di động.angularjs trước khi tải lên
mã 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>
mã:
$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;
});
}
};
Việc tải rất chậm trong các thiết bị di động. Làm thế nào tôi có thể nén tập tin?
nếu bạn không sử dụng ứng dụng bản địa bạn không thể nén một file cũng hầu hết các hình ảnh như jpg đã được nén như xa như tôi biết không có gì là bạn có thể làm. –
Nếu bạn đang tìm kiếm thao tác hình ảnh trước khi tải lên, điều này có thể hữu ích: http://stackoverflow.com/questions/2434458/image-resizing-client-side-with-javascript-before-upload-to-the-server –