Skip to content

Commit

Permalink
minor fixes
Browse files Browse the repository at this point in the history
  • Loading branch information
Danial Farid authored and Danial Farid committed Jan 21, 2016
1 parent 341cfe0 commit 8e673e3
Show file tree
Hide file tree
Showing 19 changed files with 117 additions and 83 deletions.
3 changes: 2 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -420,12 +420,13 @@ On your server you need to keep track of what files are being uploaded and how m
Make sure when the file is fully uploaded without any error/abort this endpoint returns zero for the file size
if you want to let the user to upload the same file again. Or optionally you could have a restart endpoint to
set that back to zero to allow re-uploading the same file.
* Optionally you can specify `resumeChunkSize` to upload the file in chunks to the server. This will allow uploading to GAE or other servers that have
* `resumeChunkSize` optionally you can specify this to upload the file in chunks to the server. This will allow uploading to GAE or other servers that have
file size limitation and trying to upload the whole request before passing it for internal processing.<br/>
If this option is set the requests will have the following extra fields:
`_chunkSize`, `_currentChunkSize`, `_chunkNumber` (zero starting), and `_totalSize` to help the server to write the uploaded chunk to
the correct position.
Uploading in chunks could slow down the overall upload time specially if the chunk size is too small.
When you provide `resumeChunkSize` option one of the `resumeSizeUrl` or `resumeSize` is mandatory to know how much of the file is uploaded so far.



Expand Down
2 changes: 1 addition & 1 deletion demo/src/main/webapp/js/FileAPI.min.js

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

33 changes: 20 additions & 13 deletions demo/src/main/webapp/js/ng-file-upload-all.js
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
* progress, resize, thumbnail, preview, validation and CORS
* FileAPI Flash shim for old browsers not supporting FormData
* @author Danial <[email protected]>
* @version 11.2.0
* @version 11.2.1
*/

(function () {
Expand Down Expand Up @@ -424,7 +424,7 @@ if (!window.FileReader) {
* AngularJS file upload directives and services. Supoorts: file upload/drop/paste, resume, cancel/abort,
* progress, resize, thumbnail, preview, validation and CORS
* @author Danial <[email protected]>
* @version 11.2.0
* @version 11.2.1
*/

if (window.XMLHttpRequest && !(window.FileAPI && FileAPI.shouldLoad)) {
Expand All @@ -445,7 +445,7 @@ if (window.XMLHttpRequest && !(window.FileAPI && FileAPI.shouldLoad)) {

var ngFileUpload = angular.module('ngFileUpload', []);

ngFileUpload.version = '11.2.0';
ngFileUpload.version = '11.2.1';

ngFileUpload.service('UploadBase', ['$http', '$q', '$timeout', function ($http, $q, $timeout) {
var upload = this;
Expand Down Expand Up @@ -559,6 +559,10 @@ ngFileUpload.service('UploadBase', ['$http', '$q', '$timeout', function ($http,
throw e;
});
} else {
if (config._chunkSize) {
config._start = 0;
config._end = config._start + config._chunkSize;
}
uploadWithAngular();
}

Expand Down Expand Up @@ -2453,7 +2457,7 @@ ngFileUpload.service('UploadExif', ['UploadResize', '$q', function (UploadResize
}
}

upload.readOrientation = function(file) {
upload.readOrientation = function (file) {
var defer = $q.defer();
var reader = new FileReader();
var slicedFile = file.slice(0, 64 * 1024);
Expand All @@ -2462,45 +2466,48 @@ ngFileUpload.service('UploadExif', ['UploadResize', '$q', function (UploadResize
return defer.reject(e);
};
reader.onload = function (e) {
var result = {orientation: 1};
var view = new DataView(this.result);
if (view.getUint16(0, false) !== 0xFFD8) return defer.reject();
if (view.getUint16(0, false) !== 0xFFD8) return defer.resolve(result);

var length = view.byteLength,
offset = 2;
while (offset < length) {
var marker = view.getUint16(offset, false);
offset += 2;
if (marker === 0xFFE1) {
if (view.getUint32(offset += 2, false) !== 0x45786966) return defer.reject();
if (view.getUint32(offset += 2, false) !== 0x45786966) return defer.resolve(result);

var little = view.getUint16(offset += 6, false) === 0x4949;
offset += view.getUint32(offset + 4, little);
var tags = view.getUint16(offset, little);
offset += 2;
for (var i = 0; i < tags; i++)
if (view.getUint16(offset + (i * 12), little) === 0x0112) {
var orientation = view.getUint16(offset + (i * 12) + 8, little);
var result = {orientation: orientation};
if (orientation >= 2 && orientation <= 8) {
view.setUint16(offset + (i * 12) + 8, 1, little);
result.fixedArrayBuffer = e.target.result;
}
result.orientation = orientation;
return defer.resolve(result);
}
} else if ((marker & 0xFF00) !== 0xFF00) break;
else offset += view.getUint16(offset, false);
}
defer.reject();
return defer.resolve(result);
};
return defer.promise;
};

function arrayBufferToBase64( buffer ) {
function arrayBufferToBase64(buffer) {
var binary = '';
var bytes = new Uint8Array( buffer );
var bytes = new Uint8Array(buffer);
var len = bytes.byteLength;
for (var i = 0; i < len; i++) {
binary += String.fromCharCode( bytes[ i ] );
binary += String.fromCharCode(bytes[i]);
}
return window.btoa( binary );
return window.btoa(binary);
}

upload.applyExifRotation = function (file) {
Expand Down Expand Up @@ -2545,7 +2552,7 @@ ngFileUpload.service('UploadExif', ['UploadResize', '$q', function (UploadResize
return deferred.promise;
};

upload.restoreExif = function(orig, resized) {
upload.restoreExif = function (orig, resized) {
var ExifRestorer = {};

ExifRestorer.KEY_STR = 'ABCDEFGHIJKLMNOP' +
Expand Down
6 changes: 3 additions & 3 deletions demo/src/main/webapp/js/ng-file-upload-all.min.js

Large diffs are not rendered by default.

2 changes: 1 addition & 1 deletion demo/src/main/webapp/js/ng-file-upload-shim.js
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
* progress, resize, thumbnail, preview, validation and CORS
* FileAPI Flash shim for old browsers not supporting FormData
* @author Danial <[email protected]>
* @version 11.2.0
* @version 11.2.1
*/

(function () {
Expand Down
2 changes: 1 addition & 1 deletion demo/src/main/webapp/js/ng-file-upload-shim.min.js

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

31 changes: 19 additions & 12 deletions demo/src/main/webapp/js/ng-file-upload.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
* AngularJS file upload directives and services. Supoorts: file upload/drop/paste, resume, cancel/abort,
* progress, resize, thumbnail, preview, validation and CORS
* @author Danial <[email protected]>
* @version 11.2.0
* @version 11.2.1
*/

if (window.XMLHttpRequest && !(window.FileAPI && FileAPI.shouldLoad)) {
Expand All @@ -23,7 +23,7 @@ if (window.XMLHttpRequest && !(window.FileAPI && FileAPI.shouldLoad)) {

var ngFileUpload = angular.module('ngFileUpload', []);

ngFileUpload.version = '11.2.0';
ngFileUpload.version = '11.2.1';

ngFileUpload.service('UploadBase', ['$http', '$q', '$timeout', function ($http, $q, $timeout) {
var upload = this;
Expand Down Expand Up @@ -137,6 +137,10 @@ ngFileUpload.service('UploadBase', ['$http', '$q', '$timeout', function ($http,
throw e;
});
} else {
if (config._chunkSize) {
config._start = 0;
config._end = config._start + config._chunkSize;
}
uploadWithAngular();
}

Expand Down Expand Up @@ -2031,7 +2035,7 @@ ngFileUpload.service('UploadExif', ['UploadResize', '$q', function (UploadResize
}
}

upload.readOrientation = function(file) {
upload.readOrientation = function (file) {
var defer = $q.defer();
var reader = new FileReader();
var slicedFile = file.slice(0, 64 * 1024);
Expand All @@ -2040,45 +2044,48 @@ ngFileUpload.service('UploadExif', ['UploadResize', '$q', function (UploadResize
return defer.reject(e);
};
reader.onload = function (e) {
var result = {orientation: 1};
var view = new DataView(this.result);
if (view.getUint16(0, false) !== 0xFFD8) return defer.reject();
if (view.getUint16(0, false) !== 0xFFD8) return defer.resolve(result);

var length = view.byteLength,
offset = 2;
while (offset < length) {
var marker = view.getUint16(offset, false);
offset += 2;
if (marker === 0xFFE1) {
if (view.getUint32(offset += 2, false) !== 0x45786966) return defer.reject();
if (view.getUint32(offset += 2, false) !== 0x45786966) return defer.resolve(result);

var little = view.getUint16(offset += 6, false) === 0x4949;
offset += view.getUint32(offset + 4, little);
var tags = view.getUint16(offset, little);
offset += 2;
for (var i = 0; i < tags; i++)
if (view.getUint16(offset + (i * 12), little) === 0x0112) {
var orientation = view.getUint16(offset + (i * 12) + 8, little);
var result = {orientation: orientation};
if (orientation >= 2 && orientation <= 8) {
view.setUint16(offset + (i * 12) + 8, 1, little);
result.fixedArrayBuffer = e.target.result;
}
result.orientation = orientation;
return defer.resolve(result);
}
} else if ((marker & 0xFF00) !== 0xFF00) break;
else offset += view.getUint16(offset, false);
}
defer.reject();
return defer.resolve(result);
};
return defer.promise;
};

function arrayBufferToBase64( buffer ) {
function arrayBufferToBase64(buffer) {
var binary = '';
var bytes = new Uint8Array( buffer );
var bytes = new Uint8Array(buffer);
var len = bytes.byteLength;
for (var i = 0; i < len; i++) {
binary += String.fromCharCode( bytes[ i ] );
binary += String.fromCharCode(bytes[i]);
}
return window.btoa( binary );
return window.btoa(binary);
}

upload.applyExifRotation = function (file) {
Expand Down Expand Up @@ -2123,7 +2130,7 @@ ngFileUpload.service('UploadExif', ['UploadResize', '$q', function (UploadResize
return deferred.promise;
};

upload.restoreExif = function(orig, resized) {
upload.restoreExif = function (orig, resized) {
var ExifRestorer = {};

ExifRestorer.KEY_STR = 'ABCDEFGHIJKLMNOP' +
Expand Down
7 changes: 3 additions & 4 deletions demo/src/main/webapp/js/ng-file-upload.min.js

Large diffs are not rendered by default.

2 changes: 1 addition & 1 deletion dist/FileAPI.min.js

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

Loading

0 comments on commit 8e673e3

Please sign in to comment.