Skip to content

Commit

Permalink
Support spaces in file and folder names
Browse files Browse the repository at this point in the history
  • Loading branch information
dvonlehman committed May 24, 2016
1 parent 5971d24 commit e92fe0f
Show file tree
Hide file tree
Showing 3 changed files with 16 additions and 1 deletion.
4 changes: 3 additions & 1 deletion lib/s3.js
Expand Up @@ -53,7 +53,7 @@ module.exports = function(options) {

function getObject(req, res, next) {
// This will get everything in the path following the mountpath
var s3Key = req.originalUrl.substr(req.baseUrl.length + 1);
var s3Key = decodeURIComponent(req.originalUrl.substr(req.baseUrl.length + 1));

// Chop off the querystring, it causes problems with SDK.
var queryIndex = s3Key.indexOf('?');
Expand All @@ -72,6 +72,8 @@ module.exports = function(options) {
Key: options.prefix ? urljoin(options.prefix, s3Key) : s3Key
};

debug('get s3 object with key %s', s3Params.Key);

if (req.headers['if-none-match']) {
s3Params.IfNoneMatch = req.headers['if-none-match'];
}
Expand Down
Binary file added test/fixtures/pdf sample.pdf
Binary file not shown.
13 changes: 13 additions & 0 deletions test/s3.js
Expand Up @@ -316,6 +316,19 @@ describe('S3Storage', function() {
.expect(200)
.end(done);
});

it('handles folders and files with spaces', function(done) {
var key = urljoin(encodeURIComponent('sample pdfs'), encodeURIComponent('pdf sample.pdf'));
this.s3.get('/' + BUCKET_NAME + '/' + key, function(req, res, next) {
res.set('content-type', 'application/pdf');
res.sendFile(path.join(__dirname, './fixtures/pdf sample.pdf'));
});

supertest(self.app)
.get('/s3-proxy/' + key)
.expect(200)
.end(done);
});
});

function sendS3Error(res, status, code) {
Expand Down

0 comments on commit e92fe0f

Please sign in to comment.