Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

upload object #500

Merged
merged 4 commits into from
Mar 21, 2024
Merged

upload object #500

merged 4 commits into from
Mar 21, 2024

Conversation

rrr523
Copy link
Collaborator

@rrr523 rrr523 commented Mar 20, 2024

Description

New API

object.delegateUploadObject

Allow uploading objects by sp directly, no need for createObject tx.

upload

const uploadRes = await client.object.delegateUploadObject(
  {
    bucketName: 'foo'
    objectName: 'bar',
    body: file,
    delegatedOpts: {
      visibility: VisibilityType.VISIBILITY_TYPE_PUBLIC_READ,
    },
  },
  {
    type: 'EDDSA',
    domain: window.location.origin,
    seed: offChainData.seedString,
    address,
  },
);

resumable upload

const uploadRes = await client.object.delegateUploadObject(
  {
    bucketName: 'foo'
    objectName: 'bar',
    body: file,
    delegatedOpts: {
      visibility: VisibilityType.VISIBILITY_TYPE_PUBLIC_READ,
    },
    resumableOpts: {
      partSize: 1024 * 1024 * 16,
      disableResumable: false,
    },
  },
  {
    type: 'EDDSA',
    domain: window.location.origin,
    seed: offChainData.seedString,
    address,
  },
);

bucket.toggleSpAsDelegatedAgent

If toggle, sp's delegated uploading is disabled.

const toggleSpAsDelegatedAgentTx = await client.bucket.toggleSpAsDelegatedAgent({
  bucketName: 'foo',
  operator: address,
});

object.getObjectUploadProgress

Returns the status of an object including the uploading progress.

await client.object.getObjectUploadProgress('bucketName', objectName', {
  type: 'EDDSA',
  domain: window.location.origin,
  seed: offChainData.seedString,
  address,
})

API Changes

object.uploadObject

  • change txnHash param as optional (If it is not set, it will be found automatically, but one more request will be made.)
  • add resumableOpts param (optional)

upload

await client.object.uploadObject(
  {
    bucketName: 'bucketName',
    objectName: 'objectName',
    body: file,
    txnHash: '0x....',
  },
  {
    type: 'EDDSA',
    domain: window.location.origin,
    seed: offChainData.seedString,
    address,
  },
);

resumable upload

await client.object.uploadObject(
  {
    bucketName: 'bucketName',
    objectName: 'objectName',
    body: file,
    resumableOpts: {
      partSize: 1024 * 1024 * 16,
      disableResumable: false,
    },
  },
  {
    type: 'EDDSA',
    domain: window.location.origin,
    seed: offChainData.seedString,
    address,
  },
)

Copy link

codesandbox bot commented Mar 20, 2024

Review or Edit in CodeSandbox

Open the branch in Web EditorVS CodeInsiders

Open Preview

Copy link

changeset-bot bot commented Mar 20, 2024

🦋 Changeset detected

Latest commit: 1456f54

The changes in this PR will be included in the next version bump.

This PR includes changesets to release 3 packages
Name Type
@bnb-chain/greenfield-js-sdk Patch
@demo/wallet Patch
@demo/nodejs Patch

Not sure what this means? Click here to learn what changesets are.

Click here if you're a maintainer who wants to add another changeset to this PR

Copy link

vercel bot commented Mar 20, 2024

The latest updates on your projects. Learn more about Vercel for Git ↗︎

Name Status Preview Comments Updated (UTC)
greenfield-js-sdk-nextjs-h2q3 ❌ Failed (Inspect) Mar 21, 2024 3:11pm

@rrr523 rrr523 changed the title Feat/delegate upload upload object Mar 20, 2024
@rrr523 rrr523 marked this pull request as ready for review March 21, 2024 15:20
@rrr523 rrr523 merged commit c7cf96f into alpha Mar 21, 2024
6 of 7 checks passed
@rrr523 rrr523 deleted the feat/delegate_upload branch March 21, 2024 15:20
@github-actions github-actions bot mentioned this pull request Apr 30, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

1 participant