Skip to content

Commit

Permalink
fix: add binary in get object example
Browse files Browse the repository at this point in the history
  • Loading branch information
aprilyang committed Nov 20, 2023
1 parent 4448c1b commit 8039309
Show file tree
Hide file tree
Showing 2 changed files with 24 additions and 4 deletions.
14 changes: 12 additions & 2 deletions docs/examples/get_object.md
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,13 @@ const config = new Config({
access_key_id: 'YOUR-ACCESS-KEY-ID',
secret_access_key: 'YOUR-SECRET-ACCESS-KEY',
getAxiosConfig: function(operation) {
return { responseType: 'arraybuffer' };
return {
// The data type response can be 'arraybuffer', 'blob', 'document', 'json', 'text', 'stream', default 'json'
responseType: 'arraybuffer',
// indicates encoding to use for decoding responses, default 'utf8'
// Note: Ignored for `responseType` of 'stream' or client-side requests
responseEncoding: 'binary',
};
},
});

Expand All @@ -41,7 +47,11 @@ import fs from 'fs';
* @return {Promise} axios response
*/
bucket.getObject(object_key).then((response) => {
fs.writeFile(`./${object_key}`, response.data, { flag: 'wx' }, (error) => {
fs.writeFile(`./${object_key}`, response.data, {
flag: 'wx',
// default utf8
encoding: 'binary',
}, (error) => {
console.log(error);
});
}).catch((error) => {
Expand Down
14 changes: 12 additions & 2 deletions docs/examples/get_object_zh-CN.md
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,13 @@ const config = new Config({
access_key_id: 'YOUR-ACCESS-KEY-ID',
secret_access_key: 'YOUR-SECRET-ACCESS-KEY',
getAxiosConfig: function(operation) {
return { responseType: 'arraybuffer' };
return {
// 表示服务器响应的数据类型,可以是 'arraybuffer', 'blob', 'document', 'json', 'text', 'stream',默认 json
responseType: 'arraybuffer',
// 用于解码响应的编码,默认 utf8
// Note: Ignored for `responseType` of 'stream' or client-side requests
responseEncoding: 'binary',
};
},
});

Expand All @@ -41,7 +47,11 @@ import fs from 'fs';
* @return {Promise} axios response
*/
bucket.getObject(object_key).then((response) => {
fs.writeFile(`./${object_key}`, response.data, { flag: 'wx' }, (error) => {
fs.writeFile(`./${object_key}`, response.data, {
flag: 'wx',
// 编码,默认 utf8
encoding: 'binary',
}, (error) => {
console.log(error);
});
}).catch((error) => {
Expand Down

0 comments on commit 8039309

Please sign in to comment.