JSFiddle - React, Tailwind, and code Playground
HTML
<script src="http://angular-file-upload.appspot.com/js/ng-file-upload-shim.js"></script>
<script src="http://angular-file-upload.appspot.com/js/ng-file-upload.js"></script>
<div ng-app="fileUpload" ng-controller="MyCtrl">
Drop File:
<div ngf-drop ngf-select ng-model="uploadedImages" class="drop-box"
ngf-drag-over-class="'dragover'" ngf-multiple="true" ngf-allow-dir="true"
accept="image/*"
ngf-keep="'distinct'"
ngf-pattern="'image/*'">Drop images here or click to upload</div>
<div ngf-no-file-drop>File Drag/Drop is not supported for this browser</div>
<img ng-repeat="image in uploadedImages" ngf-src="image"
ng-click="setSelectedImage(image)" ng-class="{selected: image.name === selectedImage.name}"
>
<br>
<textarea ng-show="selectedImage" rows="3" class="custom-scroll ng-pristine ng-valid" ng-model="selectedImage.decr"></textarea>
</div>
CSS
.button {
-moz-appearance: button;
/* Firefox */
-webkit-appearance: button;
/* Safari and Chrome */
padding: 10px;
margin: 10px;
width: 70px;
}
.drop-box {
background: #F8F8F8;
border: 5px dashed #DDD;
width: 200px;
height: 65px;
text-align: center;
padding-top: 25px;
margin: 10px;
}
.dragover {
border: 5px dashed blue;
}
img {
max-width: 100px;
max-height: 100px;
margin: 4px;
border: 4px solid #fff;
}
.selected{
border: 4px ridge #3B9FF3;
}
JavaScript
//inject angular file upload directives and services.
var app = angular.module('fileUpload', ['ngFileUpload']);
app.controller('MyCtrl', ['$scope', 'Upload', '$timeout', function ($scope, Upload, $timeout) {
$scope.selectedImage = null;
$scope.setSelectedImage = function (image) {
$scope.selectedImage = image;
};
$scope.$watch('files', function () {
$scope.upload($scope.files);
console.log($scope.files.length)
});
$scope.$watch('file', function () {
if ($scope.file != null) {
$scope.files = [$scope.file];
}
});
$scope.log = '';
$scope.upload = function (files) {
console.log(files.length)
if (files && files.length) {
for (var i = 0; i < files.length; i++) {
var file = files[i];
if (!file.$error) {
Upload.upload({
url: 'https://angular-file-upload-cors-srv.appspot.com/upload',
data: {
username: $scope.username,
file: file
}
}).then(function (resp) {
$timeout(function() {
$scope.log = 'file: ' +
resp.config.data.file.name +
', Response: ' + JSON.stringify(resp.data) +
'\n' + $scope.log;
});
}, null, function (evt) {
var progressPercentage = parseInt(100.0 *
evt.loaded / evt.total);
$scope.log = 'progress: ' + progressPercentage +
'% ' + evt.config.data.file.name + '\n' +
$scope.log;
});
}
}
}
};
}]);