Skip to content

Commit

Permalink
Browse files Browse the repository at this point in the history
  • Loading branch information
Danial Farid authored and Danial Farid committed Sep 14, 2014
1 parent 01379c8 commit f92e8ff
Show file tree
Hide file tree
Showing 15 changed files with 65 additions and 29 deletions.
2 changes: 1 addition & 1 deletion demo/.classpath
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
<?xml version="1.0" encoding="UTF-8"?>
<classpath>
<classpathentry kind="src" path="src"/>
<classpathentry kind="con" path="org.eclipse.jdt.launching.JRE_CONTAINER"/>
<classpathentry kind="lib" path="war/WEB-INF/lib/commons-fileupload-1.3.jar"/>
<classpathentry kind="con" path="com.google.appengine.eclipse.core.GAE_CONTAINER"/>
<classpathentry kind="con" path="org.eclipse.jdt.launching.JRE_CONTAINER"/>
<classpathentry kind="output" path="war/WEB-INF/classes"/>
</classpath>
27 changes: 23 additions & 4 deletions demo/src/com/df/angularfileupload/FileUpload.java
Original file line number Diff line number Diff line change
Expand Up @@ -22,16 +22,30 @@ public class FileUpload extends HttpServlet {
protected void service(HttpServletRequest req, HttpServletResponse res) throws ServletException, IOException {
try {
StringBuilder sb = new StringBuilder("{\"result\": [");

int errorCode = 0;
String errorMsg = null;

if (req.getHeader("Content-Type") != null
&& req.getHeader("Content-Type").startsWith("multipart/form-data")) {
ServletFileUpload upload = new ServletFileUpload();

FileItemIterator iterator = upload.getItemIterator(req);

while (iterator.hasNext()) {
sb.append("{");
FileItemStream item = iterator.next();
if (item.getFieldName() != null && item.getFieldName().equals("errorCode")) {
String val = read(item.openStream());
try {
errorCode = Integer.parseInt(val);
} catch(NumberFormatException e) {}
continue;
}
if (item.getFieldName() != null && item.getFieldName().equals("errorMessage")) {
String val = read(item.openStream());
errorMsg = val;
continue;
}
sb.append("{");
sb.append("\"fieldName\":\"").append(item.getFieldName()).append("\",");
if (item.getName() != null) {
sb.append("\"name\":\"").append(item.getName()).append("\",");
Expand Down Expand Up @@ -62,8 +76,13 @@ protected void service(HttpServletRequest req, HttpServletResponse res) throws S
}
}
sb.append("}}");

res.getWriter().write(sb.toString());

if (errorCode != 0) {
res.setStatus(errorCode);
res.getWriter().write(errorMsg);
} else {
res.getWriter().write(sb.toString());
}
} catch (Exception ex) {
throw new ServletException(ex);
}
Expand Down
2 changes: 1 addition & 1 deletion demo/war/WEB-INF/appengine-web.xml
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
<?xml version="1.0" encoding="utf-8"?>
<appengine-web-app xmlns="http://appengine.google.com/ns/1.0">
<application>angular-file-upload</application>
<version>1-6-4</version>
<version>1-6-5</version>

<!--
Allows App Engine to send multiple requests to one instance in parallel:
Expand Down
2 changes: 1 addition & 1 deletion demo/war/common.css
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ body {
}

.upload-button {
width: 160px;
width: 170px;
Height: 30px;
display: inline-block;
line-height: 30px;
Expand Down
6 changes: 5 additions & 1 deletion demo/war/index.html
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@
//flashUrl: 'yourcdn.com/js/FileAPI.flash.swf'
};
</script>
<!-- <script src="//code.jquery.com/jquery-1.9.0.min.js"></script> -->
<script src="js/angular-file-upload-shim.js"></script>
<script type="text/javascript">
// load angularjs specific version
Expand Down Expand Up @@ -66,6 +67,8 @@ <h3>
<br/>
<input type="checkbox" ng-model="uploadRightAway">Upload right away
<br/>
<input type="checkbox" ng-model="generateErrorOnServer">Make server return error code: <input type="text" ng-model="serverErrorCode"> message: <input type="text" ng-model="serverErrorMsg">
<br/>
<div class="err" ng-show="errorMsg != null">{{errorMsg}}</div>
<br/>
Progress:
Expand Down Expand Up @@ -100,6 +103,7 @@ <h3>
</ul>
</div>
</div>
<div style="position:fixed;bottom:10px;right:10px;font-size:smaller;color:#777">Last update: 2014-07-29</div>
<a style="position:fixed;bottom:10px;right:10px;font-size:smaller;" href="https://github.com/danialfarid/angular-file-upload/issues/new">Feedback/Issues</a>
<div style="position:fixed;bottom:30px;right:10px;font-size:smaller;color:#777">Last update: 2014-07-29</div>
</body>
</html>
15 changes: 10 additions & 5 deletions demo/war/js/angular-file-upload.js
Original file line number Diff line number Diff line change
Expand Up @@ -152,6 +152,13 @@ angularFileUpload.directive('ngFileSelect', [ '$parse', '$timeout', function($pa
fileElem.css("top", 0).css("bottom", 0).css("left", 0).css("right", 0).css("width", "100%").
css("opacity", 0).css("position", "absolute").css('filter', 'alpha(opacity=0)');
elem.append(fileElem);
// if (fileElem.parent()[0] != elem[0]) {
// //fix #298
// elem.wrap('<span>');
// elem.css("z-index", "-1000")
// elem.parent().append(fileElem);
// elem = elem.parent();
// }
if (elem.css("position") === '' || elem.css("position") === 'static') {
elem.css("position", "relative");
}
Expand Down Expand Up @@ -205,11 +212,10 @@ angularFileUpload.directive('ngFileDrop', [ '$parse', '$timeout', '$location', f
if ('draggable' in document.createElement('span')) {
var leaveTimeout = null;
elem[0].addEventListener("dragover", function(evt) {
evt.stopPropagation();
evt.preventDefault();
$timeout.cancel(leaveTimeout);
if (!elem[0].__drag_over_class_) {
if (attr['ngFileDragOverClass'].search(/\) *$/) > -1) {
if (attr['ngFileDragOverClass'] && attr['ngFileDragOverClass'].search(/\) *$/) > -1) {
dragOverClassFn = $parse(attr['ngFileDragOverClass']);
var dragOverClass = dragOverClassFn(scope, {
$event : evt
Expand All @@ -222,7 +228,6 @@ angularFileUpload.directive('ngFileDrop', [ '$parse', '$timeout', '$location', f
elem.addClass(elem[0].__drag_over_class_);
}, false);
elem[0].addEventListener("dragenter", function(evt) {
evt.stopPropagation();
evt.preventDefault();
}, false);
elem[0].addEventListener("dragleave", function(evt) {
Expand All @@ -233,7 +238,6 @@ angularFileUpload.directive('ngFileDrop', [ '$parse', '$timeout', '$location', f
}, false);
var fn = $parse(attr['ngFileDrop']);
elem[0].addEventListener("drop", function(evt) {
evt.stopPropagation();
evt.preventDefault();
elem.removeClass(elem[0].__drag_over_class_);
elem[0].__drag_over_class_ = null;
Expand All @@ -251,7 +255,8 @@ angularFileUpload.directive('ngFileDrop', [ '$parse', '$timeout', '$location', f

function extractFiles(evt, callback) {
var files = [], items = evt.dataTransfer.items;
if (items && items.length > 0 && items[0].webkitGetAsEntry && $location.protocol() != 'file') {
if (items && items.length > 0 && items[0].webkitGetAsEntry && $location.protocol() != 'file' &&
items[0].webkitGetAsEntry().isDirectory) {
for (var i = 0; i < items.length; i++) {
var entry = items[i].webkitGetAsEntry();
if (entry != null) {
Expand Down
7 changes: 5 additions & 2 deletions demo/war/js/upload.js
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@

angular.module('fileUpload', [ 'angularFileUpload' ]);

//var uploadUrl = 'http://angular-file-upload-cors-srv.appspot.com/upload';
var uploadUrl = 'http://angular-file-upload-cors-srv.appspot.com/upload';
window.uploadUrl = window.uploadUrl || 'upload';

var MyCtrl = [ '$scope', '$http', '$timeout', '$upload', function($scope, $http, $timeout, $upload) {
Expand Down Expand Up @@ -66,7 +66,9 @@ var MyCtrl = [ '$scope', '$http', '$timeout', '$upload', function($scope, $http,
method: $scope.httpMethod,
headers: {'my-header': 'my-header-value'},
data : {
myModel : $scope.myModel
myModel : $scope.myModel,
errorCode: $scope.generateErrorOnServer && $scope.serverErrorCode,
errorMessage: $scope.generateErrorOnServer && $scope.serverErrorMsg
},
/* formDataAppender: function(fd, key, val) {
if (angular.isArray(val)) {
Expand Down Expand Up @@ -131,4 +133,5 @@ var MyCtrl = [ '$scope', '$http', '$timeout', '$upload', function($scope, $http,
}
return hasFile ? "dragover" : "dragover-err";
};

} ];
2 changes: 1 addition & 1 deletion dist/angular-file-upload-html5-shim.js
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
/**!
* AngularJS file upload shim for angular XHR HTML5 browsers
* @author Danial <danial.farid@gmail.com>
* @version 1.6.5
* @version 1.6.6
*/
if (window.XMLHttpRequest) {
if (window.FormData) {
Expand Down
2 changes: 1 addition & 1 deletion dist/angular-file-upload-html5-shim.min.js

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion dist/angular-file-upload-shim.js
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
/**!
* AngularJS file upload shim for HTML5 FormData
* @author Danial <danial.farid@gmail.com>
* @version 1.6.5
* @version 1.6.6
*/
(function() {

Expand Down
2 changes: 1 addition & 1 deletion dist/angular-file-upload-shim.min.js

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

17 changes: 11 additions & 6 deletions dist/angular-file-upload.js
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
/**!
* AngularJS file upload/drop directive with http post and progress
* @author Danial <danial.farid@gmail.com>
* @version 1.6.5
* @version 1.6.6
*/
(function() {

Expand Down Expand Up @@ -152,6 +152,13 @@ angularFileUpload.directive('ngFileSelect', [ '$parse', '$timeout', function($pa
fileElem.css("top", 0).css("bottom", 0).css("left", 0).css("right", 0).css("width", "100%").
css("opacity", 0).css("position", "absolute").css('filter', 'alpha(opacity=0)');
elem.append(fileElem);
// if (fileElem.parent()[0] != elem[0]) {
// //fix #298
// elem.wrap('<span>');
// elem.css("z-index", "-1000")
// elem.parent().append(fileElem);
// elem = elem.parent();
// }
if (elem.css("position") === '' || elem.css("position") === 'static') {
elem.css("position", "relative");
}
Expand Down Expand Up @@ -205,11 +212,10 @@ angularFileUpload.directive('ngFileDrop', [ '$parse', '$timeout', '$location', f
if ('draggable' in document.createElement('span')) {
var leaveTimeout = null;
elem[0].addEventListener("dragover", function(evt) {
evt.stopPropagation();
evt.preventDefault();
$timeout.cancel(leaveTimeout);
if (!elem[0].__drag_over_class_) {
if ((attr['ngFileDragOverClass'])&&(attr['ngFileDragOverClass'].search(/\) *$/) > -1)) {
if (attr['ngFileDragOverClass'] && attr['ngFileDragOverClass'].search(/\) *$/) > -1) {
dragOverClassFn = $parse(attr['ngFileDragOverClass']);
var dragOverClass = dragOverClassFn(scope, {
$event : evt
Expand All @@ -222,7 +228,6 @@ angularFileUpload.directive('ngFileDrop', [ '$parse', '$timeout', '$location', f
elem.addClass(elem[0].__drag_over_class_);
}, false);
elem[0].addEventListener("dragenter", function(evt) {
evt.stopPropagation();
evt.preventDefault();
}, false);
elem[0].addEventListener("dragleave", function(evt) {
Expand All @@ -233,7 +238,6 @@ angularFileUpload.directive('ngFileDrop', [ '$parse', '$timeout', '$location', f
}, false);
var fn = $parse(attr['ngFileDrop']);
elem[0].addEventListener("drop", function(evt) {
evt.stopPropagation();
evt.preventDefault();
elem.removeClass(elem[0].__drag_over_class_);
elem[0].__drag_over_class_ = null;
Expand All @@ -251,7 +255,8 @@ angularFileUpload.directive('ngFileDrop', [ '$parse', '$timeout', '$location', f

function extractFiles(evt, callback) {
var files = [], items = evt.dataTransfer.items;
if (items && items.length > 0 && items[0].webkitGetAsEntry && $location.protocol() != 'file') {
if (items && items.length > 0 && items[0].webkitGetAsEntry && $location.protocol() != 'file' &&
items[0].webkitGetAsEntry().isDirectory) {
for (var i = 0; i < items.length; i++) {
var entry = items[i].webkitGetAsEntry();
if (entry != null) {
Expand Down
Loading

0 comments on commit f92e8ff

Please sign in to comment.