Skip to main content

Object

cancelCreateObject Tx

Send CancelCreateObject txn to greenfield chain.

paramsdescription
operatorthe account address of the operator
bucketNamethe name of the bucket
objectNamethe name of the object

createFolder Storage Provider Tx

Send create empty object txn to greenfield chain.

paramsdescription
bucketNamebucket name
objectNamefolder name, end with /
creatorthe creator of object
visibilityVisibilityType
redundancyTypeRedundancyType
const tx = await client.object.createFolder(
{
bucketName: createObjectInfo.bucketName,
objectName: createObjectInfo.objectName + '/',
creator: address,
redundancyType: RedundancyType.REDUNDANCY_EC_TYPE,
visibility: VisibilityType.VISIBILITY_TYPE_PRIVATE,
}
);
tip

This is only construct tx, next need simulate and broadcast

createObject

Creating object and send createObject txn to greenfield chain.

paramsdescription
bucketNamebucket name
objectNameobject name
creatorthe creator of object
visibilityVisibilityType
contentTypefile type
redundancyTypeRedundancyType
payloadSizefile content Longlength
expectChecksumsfile'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)),
}
);
tip

This is only construct tx, next need simulate and broadcast

deleteObject Tx

Send DeleteObject msg to greenfield chain and return txn hash.

paramsdescription
operatorthe account address of the operator who has the DeleteObject permission of the object to be deleted
bucketNamethe name of the bucket where the object which to be deleted is stored
objectNamethe name of the object which to be deleted
Browser / Nodejs Example
const tx = await client.object.deleteObject({
bucketName: 'bucket_name',
objectName: 'object_name',
operator: '0x000..',
});
tip

This is only construct tx, next need simulate and broadcast

deleteObjectPolicy Tx

Delete the object policy of the principal.

paramsdescription
operatorthe granter who grant the permission to another principal
bucketNamethe name of the bucket
objectNamethe name of the object
principalAddrprincipal address
principalPrincipalType
Browser / Nodejs Example
const tx = await client.object.deleteObjectPolicy(
'0x000..', // operator
'bucket_name', // bucket name
'object_name', // object name
'0x000..', // principalAddr
'PRINCIPAL_TYPE_GNFD_GROUP', // PrincipalType
);
tip

This is only construct tx, next need simulate and broadcast

downloadFile Storage Provider

Download s3 object payload and return the related object info.

paramsdescription
bucketNamebucket name
objectNameobject name
await client.object.downloadFile(
{
bucketName,
objectName,
},
{
type: 'EDDSA',
address,
domain: window.location.origin,
seed: offChainData.seedString,
},
);

getObjectPolicy Query

Get the object policy info of the user specified by principalAddr.

paramsdescription
bucketNamebucket name
objectNameobject name
principalAddrprincipal address
example
const tx = await client.object.getObjectPolicy('bucket_name', 'object_name', '0x...');

getObjectPreviewUrl Storage Provider

Get the object preview url.

Browser
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.

paramsdescription
bucketNamebucket name
objectNameobject name
example
await client.object.headObject(bucketName, objectName);

headObjectById Query

Query the objectInfo on chain by object id, return the object info if exists.

example
await client.object.headObjectById('12');

listObjects Storage Provider

Lists the object info of the bucket.

paramsdescription
bucketNamebucket name
example
const res = await client.object.listObjects({
bucketName,
});

listObjectsByIds Storage Provider

List objects by object ids.

paramsdescription
idsobject ids array
example
await client.object.listObjectsByIds({
ids: ['1', '2'],
});

listObjectPolicies Storage Provider

List object policies by object info and action type.

paramsdescription
bucketNamebucket name
objectNameobject name
actionTypeActionType
example
const res = await client.object.listObjectPolicies({
bucketName: 'bucket_name',
objectName: 'object_name',
actionType: 'ACTION_GET_OBJECT',
});

putObjectPolicy Tx

paramsdescription
operatoroperator address
principalPrincipal

Apply object policy to the principal, return the txn hash.

example
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',
},
});
tip

This is only construct tx, next need simulate and broadcast

updateObjectInfo Tx

Update object info by sending message to greenfield.

paramsdescription
bucketNamebucket name
objectNameobject name
operatoroperator address
visibilityVisibilityType
example
const tx = await client.object.updateObjectInfo({
bucketName: 'bucket_name',
objectName: 'object_name',
operator: '0x...',
visibility: 'VISIBILITY_TYPE_PUBLIC_READ',
});
tip

This is only construct tx, next need simulate and broadcast

uploadObject Storage Provider

Uploading the object to bucket.

paramsdescription
bucketNamebucket name
objectNameobject name
bodyfile
txnHashcreateObject 's hash
authTypeAuthType
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,
},
);