Merge branch 'master' of https://github.com/hgouveia/loopback-component-storage into hgouveia-master
# Conflicts: # lib/storage-handler.js # test/upload-download.test.js
This commit is contained in:
commit
2cea6a0c8d
|
@ -77,6 +77,7 @@ exports.upload = function(provider, req, res, options, cb) {
|
||||||
container: container,
|
container: container,
|
||||||
name: part.filename,
|
name: part.filename,
|
||||||
type: part.mime,
|
type: part.mime,
|
||||||
|
field: part.name,
|
||||||
};
|
};
|
||||||
|
|
||||||
// Options for this file
|
// Options for this file
|
||||||
|
|
|
@ -249,6 +249,7 @@ StorageService.prototype.upload = function(req, res, options, cb) {
|
||||||
}
|
}
|
||||||
if (this.nameConflict && !options.nameConflict) {
|
if (this.nameConflict && !options.nameConflict) {
|
||||||
options.nameConflict = this.nameConflict;
|
options.nameConflict = this.nameConflict;
|
||||||
|
}
|
||||||
if (this.maxFieldsSize && !options.maxFieldsSize) {
|
if (this.maxFieldsSize && !options.maxFieldsSize) {
|
||||||
options.maxFieldsSize = this.maxFieldsSize;
|
options.maxFieldsSize = this.maxFieldsSize;
|
||||||
}
|
}
|
||||||
|
|
|
@ -1,2 +1,3 @@
|
||||||
test.jpg
|
test.jpg
|
||||||
image-*.jpg
|
image-*.jpg
|
||||||
|
customimagefield_test.jpg
|
|
@ -14,6 +14,23 @@ var path = require('path');
|
||||||
|
|
||||||
// configure errorHandler to show full error message
|
// configure errorHandler to show full error message
|
||||||
app.set('remoting', {errorHandler: {debug: true, log: false}});
|
app.set('remoting', {errorHandler: {debug: true, log: false}});
|
||||||
|
//custom route with renamer
|
||||||
|
app.post('/custom/upload', function(req, res, next) {
|
||||||
|
var options = {
|
||||||
|
container: 'album1',
|
||||||
|
getFilename: function(file, req, res) {
|
||||||
|
return file.field + '_' + file.name;
|
||||||
|
},
|
||||||
|
};
|
||||||
|
ds.connector.upload(req, res, options, function(err, result) {
|
||||||
|
if (!err) {
|
||||||
|
res.setHeader('Content-Type', 'application/json');
|
||||||
|
res.status(200).send({result: result});
|
||||||
|
} else {
|
||||||
|
res.status(500).send(err);
|
||||||
|
}
|
||||||
|
});
|
||||||
|
});
|
||||||
|
|
||||||
// expose a rest api
|
// expose a rest api
|
||||||
app.use(loopback.rest());
|
app.use(loopback.rest());
|
||||||
|
@ -166,8 +183,7 @@ describe('storage service', function() {
|
||||||
.expect('Content-Type', /json/)
|
.expect('Content-Type', /json/)
|
||||||
.expect(200, function(err, res) {
|
.expect(200, function(err, res) {
|
||||||
assert.deepEqual(res.body, {'result': {'files': {'image': [
|
assert.deepEqual(res.body, {'result': {'files': {'image': [
|
||||||
{'container': 'album1', 'name': 'test.jpg', 'type': 'image/jpeg',
|
{'container': 'album1', 'name': 'test.jpg', 'type': 'image/jpeg', 'field': 'image', 'size': 60475},
|
||||||
'size': 60475},
|
|
||||||
]}, 'fields': {}}});
|
]}, 'fields': {}}});
|
||||||
done();
|
done();
|
||||||
});
|
});
|
||||||
|
@ -217,7 +233,7 @@ describe('storage service', function() {
|
||||||
.expect('Content-Type', /json/)
|
.expect('Content-Type', /json/)
|
||||||
.expect(200, function(err, res) {
|
.expect(200, function(err, res) {
|
||||||
assert.deepEqual(res.body, {'result': {'files': {'image': [
|
assert.deepEqual(res.body, {'result': {'files': {'image': [
|
||||||
{'container': 'album1', 'name': 'image-test.jpg', 'originalFilename': 'test.jpg', 'type': 'image/jpeg', 'acl': 'public-read', 'size': 60475},
|
{'container': 'album1', 'name': 'image-test.jpg', 'originalFilename': 'test.jpg', 'type': 'image/jpeg', 'field': 'image', 'acl': 'public-read', 'size': 60475},
|
||||||
]}, 'fields': {}}});
|
]}, 'fields': {}}});
|
||||||
done();
|
done();
|
||||||
});
|
});
|
||||||
|
@ -387,4 +403,21 @@ describe('storage service', function() {
|
||||||
done();
|
done();
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
|
|
||||||
|
it('should upload a file with custom route accessing directly to the ' +
|
||||||
|
'storage connector with renamer', function(done) {
|
||||||
|
request('http://localhost:' + app.get('port'))
|
||||||
|
.post('/custom/upload')
|
||||||
|
.attach('customimagefield', path.join(__dirname, './fixtures/test.jpg'))
|
||||||
|
.set('Accept', 'application/json')
|
||||||
|
.expect('Content-Type', /json/)
|
||||||
|
.expect(200, function(err, res) {
|
||||||
|
assert.deepEqual(res.body, {'result': {'files': {'customimagefield': [
|
||||||
|
{'container': 'album1', 'name': 'customimagefield_test.jpg',
|
||||||
|
'originalFilename': 'test.jpg', 'type': 'image/jpeg',
|
||||||
|
'field': 'customimagefield', 'size': 60475},
|
||||||
|
]}, 'fields': {}}});
|
||||||
|
done();
|
||||||
|
});
|
||||||
|
});
|
||||||
});
|
});
|
||||||
|
|
Loading…
Reference in New Issue