Object
cancelCreateObject Tx
Send CancelCreateObject
txn to greenfield chain.
params | description |
---|---|
operator | the account address of the operator |
bucketName | the name of the bucket |
objectName | the name of the object |
createFolder Storage Provider Tx
Send create empty object txn to greenfield chain.
params | description |
---|---|
bucketName | bucket name |
objectName | folder name, end with / |
creator | the creator of object |
visibility | VisibilityType |
redundancyType | RedundancyType |
const tx = await client.object.createFolder(
{
bucketName: createObjectInfo.bucketName,
objectName: createObjectInfo.objectName + '/',
creator: address,
redundancyType: RedundancyType.REDUNDANCY_EC_TYPE,
visibility: VisibilityType.VISIBILITY_TYPE_PRIVATE,
}
);
createObject
Creating object and send createObject txn to greenfield chain.
params | description |
---|---|
bucketName | bucket name |
objectName | object name |
creator | the creator of object |
visibility | VisibilityType |
contentType | file type |
redundancyType | RedundancyType |
payloadSize | file content Longlength |
expectChecksums | file's expectChecksums |
const tx = await client.object.createObject(
{
bucketName: 'bucket_name',
objectName: 'object_name',
creator: '0x...',
visibility: VisibilityType.VISIBILITY_TYPE_PRIVATE,
contentType: 'json',
redundancyType: RedundancyType.REDUNDANCY_EC_TYPE,
payloadSize: Long.fromInt(13311),
expectCheckSums: expectCheckSums.map((x) => bytesFromBase64(x)),
}
);
deleteObject Tx
Send DeleteObject msg to greenfield chain and return txn hash.
params | description |
---|---|
operator | the account address of the operator who has the DeleteObject permission of the object to be deleted |
bucketName | the name of the bucket where the object which to be deleted is stored |
objectName | the name of the object which to be deleted |
const tx = await client.object.deleteObject({
bucketName: 'bucket_name',
objectName: 'object_name',
operator: '0x000..',
});
deleteObjectPolicy Tx
Delete the object policy of the principal.
params | description |
---|---|
operator | the granter who grant the permission to another principal |
bucketName | the name of the bucket |
objectName | the name of the object |
principalAddr | principal address |
principal | PrincipalType |
const tx = await client.object.deleteObjectPolicy(
'0x000..', // operator
'bucket_name', // bucket name
'object_name', // object name
'0x000..', // principalAddr
'PRINCIPAL_TYPE_GNFD_GROUP', // PrincipalType
);
downloadFile Storage Provider
Download s3 object payload and return the related object info.
params | description |
---|---|
bucketName | bucket name |
objectName | object name |
- Browser
- Nodejs
await client.object.downloadFile(
{
bucketName,
objectName,
},
{
type: 'EDDSA',
address,
domain: window.location.origin,
seed: offChainData.seedString,
},
);
await client.object.downloadFile(
{
bucketName,
objectName,
},
{
type: 'ECDSA',
privateKey: ACCOUNT_PRIVATEKEY,
},
);
getObjectPolicy Query
Get the object policy info of the user specified by principalAddr.
params | description |
---|---|
bucketName | bucket name |
objectName | object name |
principalAddr | principal address |
const tx = await client.object.getObjectPolicy('bucket_name', 'object_name', '0x...');
getObjectPreviewUrl Storage Provider
Get the object preview url.
const res = await client.object.getObjectPreviewUrl(
{
bucketName: 'bucket_name',
objectName: 'object_name',
queryMap: {
view: '1',
'X-Gnfd-User-Address': address,
'X-Gnfd-App-Domain': window.location.origin,
'X-Gnfd-Expiry-Timestamp': '2023-09-03T09%3A23%3A39Z',
},
},
{
type: 'EDDSA',
address,
domain: window.location.origin,
seed: offChainData.seedString,
},
);
headObject Query
Query the objectInfo on chain to check the object id, return the object info if exists.
params | description |
---|---|
bucketName | bucket name |
objectName | object name |
await client.object.headObject(bucketName, objectName);
headObjectById Query
Query the objectInfo on chain by object id, return the object info if exists.
await client.object.headObjectById('12');
listObjects Storage Provider
Lists the object info of the bucket.
params | description |
---|---|
bucketName | bucket name |
const res = await client.object.listObjects({
bucketName,
});
listObjectsByIds Storage Provider
List objects by object ids.
params | description |
---|---|
ids | object ids array |
await client.object.listObjectsByIds({
ids: ['1', '2'],
});
listObjectPolicies Storage Provider
List object policies by object info and action type.
params | description |
---|---|
bucketName | bucket name |
objectName | object name |
actionType | ActionType |
const res = await client.object.listObjectPolicies({
bucketName: 'bucket_name',
objectName: 'object_name',
actionType: 'ACTION_GET_OBJECT',
});
putObjectPolicy Tx
params | description |
---|---|
operator | operator address |
principal | Principal |
Apply object policy to the principal, return the txn hash.
import { PermissionTypes } from '@bnb-chain/greenfield-js-sdk';
const statement: PermissionTypes.Statement = {
effect: PermissionTypes.Effect.EFFECT_ALLOW,
actions: [PermissionTypes.ActionType.ACTION_GET_OBJECT],
resources: [],
};
await client.object.putObjectPolicy('bucket_name', 'object_name', {
operator: '0x...',
statements: [statement],
principal: {
type: PermissionTypes.PrincipalType.PRINCIPAL_TYPE_GNFD_ACCOUNT,
value: '0x0000000000000000000000000000000000000001',
},
});
updateObjectInfo Tx
Update object info by sending message to greenfield.
params | description |
---|---|
bucketName | bucket name |
objectName | object name |
operator | operator address |
visibility | VisibilityType |
const tx = await client.object.updateObjectInfo({
bucketName: 'bucket_name',
objectName: 'object_name',
operator: '0x...',
visibility: 'VISIBILITY_TYPE_PUBLIC_READ',
});
uploadObject Storage Provider
Uploading the object to bucket.
params | description |
---|---|
bucketName | bucket name |
objectName | object name |
body | file |
txnHash | createObject 's hash |
authType | AuthType |
- Browser
- Nodejs
const uploadRes = await client.object.uploadObject(
{
bucketName: createObjectInfo.bucketName,
objectName: createObjectInfo.objectName,
body: file,
txnHash: txHash,
},
{
type: 'EDDSA',
domain: window.location.origin,
seed: offChainData.seedString,
address,
},
);
const uploadRes = await client.object.uploadObject(
{
bucketName: bucketName,
objectName: objectName,
body: fileBuffer,
txnHash: createObjectTxRes.transactionHash,
},
{
type: 'ECDSA',
privateKey: ACCOUNT_PRIVATEKEY,
},
);