Skip to content

Commit

Permalink
+ imageTransform.postName; + imageOriginal: true (default)
Browse files Browse the repository at this point in the history
  • Loading branch information
RubaXa committed Jul 18, 2013
1 parent f81ca65 commit 55b9de6
Show file tree
Hide file tree
Showing 6 changed files with 99 additions and 18 deletions.
28 changes: 23 additions & 5 deletions dist/FileAPI.html5.js
Original file line number Diff line number Diff line change
Expand Up @@ -986,6 +986,7 @@
, progress: api.F
, complete: api.F
, pause: api.F
, imageOriginal: true
, chunkSize: api.chunkSize
, chunkUpoloadRetry: api.chunkUploadRetry
}, options);
Expand Down Expand Up @@ -1224,7 +1225,7 @@
, trans = api.support.transform && options.imageTransform
, Form = new api.Form
, queue = api.queue(function (){ fn(Form); })
, isOrignTrans = trans && (parseInt(trans.maxWidth || trans.minWidth || trans.width, 10) > 0 || trans.rotate || trans.crop || trans.type || trans.quality || trans.overlay)
, isOrignTrans = trans && _isOriginTransform(trans)
;

(function _addFile(file/**Object*/){
Expand Down Expand Up @@ -1257,20 +1258,24 @@
Form.append(name, images[0], filename, trans[0].type || filetype);
}
else {
var addOrigin = 0;

if( !err ){
_each(images, function (image, idx){
if( !dataURLtoBlob && !api.flashEngine ){
Form.multipart = true;
}

Form.append(name +'['+ idx +']', image, filename, trans[idx].type || filetype);
});
if( !trans[idx].postName ){
addOrigin = 1;
}

name += '[original]';
Form.append(trans[idx].postName || name +'['+ idx +']', image, filename, trans[idx].type || filetype);
});
}

if( err || options.imageOriginal ){
Form.append(name, file, filename, filetype);
Form.append(name + (addOrigin ? '[original]' : ''), file, filename, filetype);
}
}

Expand Down Expand Up @@ -1569,6 +1574,19 @@
}


function _isOriginTransform(trans){
var key;
for( key in trans ){
if( trans.hasOwnProperty(key) ){
if( !(trans[key] instanceof Object || key === 'overlay') ){
return true;
}
}
}
return false;
}


// Add default image info reader
api.addInfoReader(/^image/, function (file/**File*/, callback/**Function*/){
if( !file.__dimensions ){
Expand Down
2 changes: 1 addition & 1 deletion dist/FileAPI.html5.min.js

Large diffs are not rendered by default.

28 changes: 23 additions & 5 deletions dist/FileAPI.js
Original file line number Diff line number Diff line change
Expand Up @@ -986,6 +986,7 @@
, progress: api.F
, complete: api.F
, pause: api.F
, imageOriginal: true
, chunkSize: api.chunkSize
, chunkUpoloadRetry: api.chunkUploadRetry
}, options);
Expand Down Expand Up @@ -1224,7 +1225,7 @@
, trans = api.support.transform && options.imageTransform
, Form = new api.Form
, queue = api.queue(function (){ fn(Form); })
, isOrignTrans = trans && (parseInt(trans.maxWidth || trans.minWidth || trans.width, 10) > 0 || trans.rotate || trans.crop || trans.type || trans.quality || trans.overlay)
, isOrignTrans = trans && _isOriginTransform(trans)
;

(function _addFile(file/**Object*/){
Expand Down Expand Up @@ -1257,20 +1258,24 @@
Form.append(name, images[0], filename, trans[0].type || filetype);
}
else {
var addOrigin = 0;

if( !err ){
_each(images, function (image, idx){
if( !dataURLtoBlob && !api.flashEngine ){
Form.multipart = true;
}

Form.append(name +'['+ idx +']', image, filename, trans[idx].type || filetype);
});
if( !trans[idx].postName ){
addOrigin = 1;
}

name += '[original]';
Form.append(trans[idx].postName || name +'['+ idx +']', image, filename, trans[idx].type || filetype);
});
}

if( err || options.imageOriginal ){
Form.append(name, file, filename, filetype);
Form.append(name + (addOrigin ? '[original]' : ''), file, filename, filetype);
}
}

Expand Down Expand Up @@ -1569,6 +1574,19 @@
}


function _isOriginTransform(trans){
var key;
for( key in trans ){
if( trans.hasOwnProperty(key) ){
if( !(trans[key] instanceof Object || key === 'overlay') ){
return true;
}
}
}
return false;
}


// Add default image info reader
api.addInfoReader(/^image/, function (file/**File*/, callback/**Function*/){
if( !file.__dimensions ){
Expand Down
4 changes: 2 additions & 2 deletions dist/FileAPI.min.js

Large diffs are not rendered by default.

28 changes: 23 additions & 5 deletions lib/FileAPI.core.js
Original file line number Diff line number Diff line change
Expand Up @@ -895,6 +895,7 @@
, progress: api.F
, complete: api.F
, pause: api.F
, imageOriginal: true
, chunkSize: api.chunkSize
, chunkUpoloadRetry: api.chunkUploadRetry
}, options);
Expand Down Expand Up @@ -1133,7 +1134,7 @@
, trans = api.support.transform && options.imageTransform
, Form = new api.Form
, queue = api.queue(function (){ fn(Form); })
, isOrignTrans = trans && (parseInt(trans.maxWidth || trans.minWidth || trans.width, 10) > 0 || trans.rotate || trans.crop || trans.type || trans.quality || trans.overlay)
, isOrignTrans = trans && _isOriginTransform(trans)
;

(function _addFile(file/**Object*/){
Expand Down Expand Up @@ -1166,20 +1167,24 @@
Form.append(name, images[0], filename, trans[0].type || filetype);
}
else {
var addOrigin = 0;

if( !err ){
_each(images, function (image, idx){
if( !dataURLtoBlob && !api.flashEngine ){
Form.multipart = true;
}

Form.append(name +'['+ idx +']', image, filename, trans[idx].type || filetype);
});
if( !trans[idx].postName ){
addOrigin = 1;
}

name += '[original]';
Form.append(trans[idx].postName || name +'['+ idx +']', image, filename, trans[idx].type || filetype);
});
}

if( err || options.imageOriginal ){
Form.append(name, file, filename, filetype);
Form.append(name + (addOrigin ? '[original]' : ''), file, filename, filetype);
}
}

Expand Down Expand Up @@ -1478,6 +1483,19 @@
}


function _isOriginTransform(trans){
var key;
for( key in trans ){
if( trans.hasOwnProperty(key) ){
if( !(trans[key] instanceof Object || key === 'overlay') ){
return true;
}
}
}
return false;
}


// Add default image info reader
api.addInfoReader(/^image/, function (file/**File*/, callback/**Function*/){
if( !file.__dimensions ){
Expand Down
27 changes: 27 additions & 0 deletions tests/tests.js
Original file line number Diff line number Diff line change
Expand Up @@ -411,6 +411,33 @@ module('FileAPI');
});


test('upload + imageTransform with postName', function (){
var file = FileAPI.getFiles(uploadForm['dino.png'])[0];

stop();
FileAPI.upload({
url: 'http://rubaxa.org/FileAPI/server/ctrl.php',
files: { image: file },
imageTransform: {
'180deg': {
postName: '180deg',
width: 50,
height: 50,
rotate: 180
}
},
complete: function (err, res){
var res = FileAPI.parseJSON(res.responseText);
ok('image' in res.data._FILES);
ok('180deg' in res.data._FILES);
equal(res.data._FILES['image'].name, 'dino.png');
equal(res.data._FILES['180deg'].name, 'dino.png');
start();
}
});
});


test('WebCam', function (){
stop();
FileAPI.Camera.publish(document.getElementById('web-cam'), function (err, cam){
Expand Down

0 comments on commit 55b9de6

Please sign in to comment.