Skip to content

Commit

Permalink
chore: Upload Object (Nodejs) (#411)
Browse files Browse the repository at this point in the history
chore: Upload Object
  • Loading branch information
rrr523 authored Dec 1, 2023
1 parent 752e5fc commit bf87769
Showing 1 changed file with 22 additions and 1 deletion.
23 changes: 22 additions & 1 deletion examples/nodejs/cases/storage.js
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,11 @@ const fileBuffer = fs.readFileSync(filePath);
const extname = path.extname(filePath);
const fileType = mimeTypes.lookup(extname);

(async () => {
console.log('bucketName', bucketName);
console.log(
'objectName',
objectName,
)(async () => {
const spInfo = await selectSp();

// create bucket example:
Expand Down Expand Up @@ -86,4 +90,21 @@ const fileType = mimeTypes.lookup(extname);
});

console.log('create object success', createObjectTxRes);

const uploadRes = await client.object.uploadObject(
{
bucketName: bucketName,
objectName: objectName,
body: fileBuffer,
txnHash: createObjectTxRes.transactionHash,
},
{
type: 'ECDSA',
privateKey: ACCOUNT_PRIVATEKEY,
},
);

if (uploadRes.code === 0) {
console.log('upload object success', uploadRes);
}
})();

0 comments on commit bf87769

Please sign in to comment.