Skip to content

Commit 7fe24d0

Browse files
committed
Merge pull request #1062 from noobaa/eran_04_fixes
s3 encoding fixes
2 parents ca320a4 + e606623 commit 7fe24d0

File tree

2 files changed

+46
-4
lines changed

2 files changed

+46
-4
lines changed

src/s3/s3_controller.js

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,7 @@ let ObjectIO = require('../api/object_io');
99
let s3_errors = require('./s3_errors');
1010
let xml2js = require('xml2js');
1111
let P = require('../util/promise');
12+
let string_utils = require('../util/string_utils');
1213

1314
dbg.set_level(5);
1415

@@ -137,7 +138,7 @@ class S3Controller {
137138
},
138139
if_not_empty(_.map(reply.objects, obj => ({
139140
Contents: {
140-
Key: obj.key,
141+
Key: string_utils.encodeXML(obj.key),
141142
LastModified: to_s3_date(obj.info.create_time),
142143
ETag: obj.info.etag,
143144
Size: obj.info.size,
@@ -189,7 +190,7 @@ class S3Controller {
189190
},
190191
if_not_empty(_.map(reply.objects, obj => ({
191192
Version: {
192-
Key: obj.key,
193+
Key: string_utils.encodeXML(obj.key),
193194
VersionId: '',
194195
IsLatest: true,
195196
LastModified: to_s3_date(obj.info.create_time),
@@ -240,7 +241,7 @@ class S3Controller {
240241
},
241242
if_not_empty(_.map(reply.objects, obj => ({
242243
Upload: {
243-
Key: obj.key,
244+
Key: string_utils.encodeXML(obj.key),
244245
UploadId: obj.info.version_id,
245246
Initiated: to_s3_date(obj.info.create_time),
246247
Initiator: DEFAULT_S3_USER,
@@ -456,13 +457,14 @@ class S3Controller {
456457
* (aka copy object)
457458
*/
458459
_copy_object(req, res) {
459-
let copy_source = req.headers['x-amz-copy-source'];
460+
let copy_source = decodeURIComponent(req.headers['x-amz-copy-source']);
460461
let slash_index = copy_source.indexOf('/');
461462
let start_index = 0;
462463
if (slash_index === 0) {
463464
start_index = 1;
464465
slash_index = copy_source.indexOf('/', 1);
465466
}
467+
console.log('COPY OBJECT ',req.params.key);
466468
let source_bucket = copy_source.slice(start_index, slash_index);
467469
let source_key = copy_source.slice(slash_index + 1);
468470
let params = {

src/s3test.js

Lines changed: 40 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,40 @@
1+
'use strict';
2+
var _ = require('lodash');
3+
var P = require('./util/promise');
4+
var AWS = require('aws-sdk');
5+
var dbg = require('./util/debug_module')(__filename);
6+
7+
8+
var mys3 = new AWS.S3({
9+
accessKeyId: "AKIAJOP7ZFXOOPGL5BOA",
10+
secretAccessKey: "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",
11+
//s3ForcePathStyle: true,
12+
maxRedirects: 10
13+
});
14+
15+
var params = {
16+
Bucket: "ca-tester",
17+
};
18+
19+
return P.ninvoke(mys3, 'getBucketLocation', params)
20+
.then(function(location) {
21+
dbg.log0('location', location);
22+
//mys3.setRegion(location.LocationConstraint);
23+
mys3.config.update({
24+
region: location.LocationConstraint
25+
});
26+
return P.ninvoke(mys3, 'listObjects', params)
27+
.fail(function(error) {
28+
dbg.error('update_c2n_worklist failed to list files from cloud: sys', error, error.stack);
29+
throw new Error('update_c2n_worklist failed to list files from cloud');
30+
}).
31+
then(function(cloud_obj) {
32+
var cloud_object_list = _.map(cloud_obj.Contents, function(obj) {
33+
return {
34+
create_time: obj.LastModified,
35+
key: obj.Key
36+
};
37+
});
38+
dbg.log0('list', cloud_object_list);
39+
})
40+
});

0 commit comments

Comments
 (0)