diff --git a/README.md b/README.md index a5a7842db..b695fa42a 100644 --- a/README.md +++ b/README.md @@ -1888,6 +1888,7 @@ parameters: - [process] {String} image process params, will send with `x-oss-process` e.g.: `{process: 'image/resize,w_200'}` - [trafficLimit] {Number} traffic limit, range: `819200`~`838860800`. + - [subResource] {Object} additional signature parameters in url. - [response] {Object} set the response headers for download - [content-type] {String} set the response content type - [content-disposition] {String} set the response content disposition diff --git a/lib/common/signUtils.js b/lib/common/signUtils.js index c95e27e79..c7d6c5a02 100644 --- a/lib/common/signUtils.js +++ b/lib/common/signUtils.js @@ -103,9 +103,9 @@ exports.authorization = function authorization(accessKeyId, accessKeySecret, can * @param {String} resource * @param {Number} expires */ -exports._signatureForURL = function _signatureForURL(accessKeySecret, options, resource, expires) { +exports._signatureForURL = function _signatureForURL(accessKeySecret, options = {}, resource, expires) { const headers = {}; - const subResource = {}; + const { subResource = {} } = options; if (options.process) { const processKeyword = 'x-oss-process'; @@ -133,8 +133,6 @@ exports._signatureForURL = function _signatureForURL(accessKeySecret, options, r headers[key] = value; } else if (lowerKey.indexOf('content-type') === 0) { headers[key] = value; - } else if (lowerKey !== 'expires' && lowerKey !== 'response' && lowerKey !== 'process' && lowerKey !== 'method' && lowerKey !== 'trafficlimit') { - subResource[lowerKey] = value; } }); diff --git a/test/node/object.test.js b/test/node/object.test.js index 8c0cd88db..679a80d6d 100644 --- a/test/node/object.test.js +++ b/test/node/object.test.js @@ -951,7 +951,7 @@ describe('test/object.test.js', () => { assert.equal(urlRes.data.toString(), result.content.toString()); }); - it('should signature url with reponse limitation', async () => { + it('should signature url with response limitation', async () => { const response = { 'content-type': 'xml', 'content-language': 'zh-cn' @@ -961,6 +961,30 @@ describe('test/object.test.js', () => { assert(url.indexOf('response-content-language=zh-cn') !== -1); }); + it('should signature url with options contains other parameters', async () => { + const options = { + expires: 3600, + subResource: { + 'x-oss-process': 'image/resize,w_200', + }, + // others parameters + filename: 'test.js', + testParameters: 'xxx', + }; + const imageName = `${prefix}ali-sdk/oss/nodejs-test-signature-1024x768.png`; + const originImagePath = path.join(__dirname, 'nodejs-1024x768.png'); + path.join(__dirname, 'nodejs-processed-w200.png'); + await store.put(imageName, originImagePath, { + mime: 'image/png', + }); + + const signUrl = store.signatureUrl(imageName, options); + const processedKeyword = 'x-oss-process=image%2Fresize%2Cw_200'; + assert.equal(signUrl.match(processedKeyword), processedKeyword); + const urlRes = await urllib.request(signUrl); + assert.equal(urlRes.status, 200); + }); + it('should signature url with image processed and get object ok', async () => { const imageName = `${prefix}ali-sdk/oss/nodejs-test-signature-1024x768.png`; const originImagePath = path.join(__dirname, 'nodejs-1024x768.png');