Swan Network
English
  • Getting Started
    • Overview
    • Protocol Stack
      • Cross-chain Consensus Layer
      • Peer-to-peer (P2P) Network
      • Payment Channels
      • Service Discovery
      • Data Marketplace
      • Indexing and Caching Marketplace
      • Web3 Task Auction
      • Storage Layer
      • Computing Layer
      • CDN Layer
      • Economic System
        • Grants
        • Computing Jobs
        • Universal Basic Income (UBI)
        • Swan Provider Income
      • Token
      • Governance
        • Treasure DAO
      • Glossary
    • Contact Us
      • Social Accounts & Communities
      • Business Partnerships
    • FAQ
  • QuickStarts
    • Dive into QuickStarts
      • Swan Chain: Developing Smart Contracts with Go
  • Swan Storage Market
    • Overview
      • Swan Auction System
      • Reputation System
    • Key functionalities
      • Task Management
        • Create a New Task
        • Navigate Tasks
        • Update Tasks
        • Assign Tasks
      • My Profile
        • Register as a storage provider
      • Find Storage Providers
        • Storage Provider Details
      • Extend DataCap Terms Service
  • Swan IPFS Storage
    • Overview
      • Flink
    • Swan IPFS Storage User Guide
      • Networks
      • Setup MetaMask
    • Developer Quickstart
      • SDK
        • js MCS SDK
          • Prerequisites
          • Get Started
          • Bucket Storage
          • Onchain Storage
          • SDK JS Installation Tutorial Video
        • python MCS SDK
          • Quickstart
          • Bucket Storage
          • Onchain Storage
          • SDK Python Installation Tutorial Video
      • Additional Resources
    • Best Practice
      • Use Swan IPFS Storage as Platform Storage Solution
        • Single Organization Design
        • Multiple Organization Design
    • FAQ
  • Swan Provider
    • Overview
    • Features
    • Tutorial
      • Prerequisites
      • Installation
      • Configure and Run
      • Swan Provider Tutorial Video
    • FAQ
      • 1. Change the linked Email
      • 2. Check Storage Provider connectivity/stability
      • 3. How to stop accepting "auto-bid" deals?
      • 4. `aria2_download_dir` vs. `aria2_candidate_dirs`
      • 5. How to configure "import deals from Swan Provider" when Boostd is running normally
      • 6. A rejection msg always appears during the deal-importing process
      • 7. How to check if aria2 is running?
      • 8. No response from Swan Platform?
      • 9. Why Storage Provider status shows offline?
      • 10. How to check the Task Status?
      • 11. How to configure the Storage Provider Market?
      • 12. How to set the "ask price"?
      • 13.aria2_download_dir VS. aria2_candidate_dirs
      • 14. How to control the number of deals imported?
  • Swan Client
    • Overview
    • Basic Concepts
    • Tutorial
      • Filecoin Deal Sender
        • Installation
        • Configuration
        • Prerequisites
        • Generate CAR Files
        • Meta-CAR
        • Upload CAR Files to IPFS
        • Create a Task
      • Blockchain RPC Service
        • Deploy RPC Service
        • RPC Command Service
      • Swan Client Tutorial Video
    • FAQ
      • How to prepare data?
  • FS3
    • Overview
    • Setup your FS3
      • Prerequisites
      • Install FS3
      • FS3 Set up Video
    • FS3 User Guide
    • FS3 User Guide (Cloud Version)
  • Lagrange DAO
    • Overview
  • Development Resource
    • Swan Token Contract
      • Acquire Testnet USDC and MATIC tokens
    • Swan API
    • Swan IPFS Storage API
    • Swan IPFS Storage 2.0 API
    • Flink API
    • FS3 API
    • API keys
  • Swan Testnet
    • Swan Jupiter Testnet
      • How to Participate
      • Before You Get Started
      • Network Early Adopter
      • Computing Provider Setup
        • Prerequisites
        • Install the Kubernetes
        • Install and config the Nginx
        • Install the Hardware resource-exporter
        • Install the Redis service
        • Build and config the Computing Provider
        • Install AI Inference Dependency(Optional)
        • Start the Computing Provider
        • CLI of Computing Provider
        • FAQ
      • FAQ
Powered by GitBook
On this page
  • Create a Bucket
  • Get Bucket(s)
  • Delete Bucket
  • Rename Bucket
  • Create Folder
  • Upload File
  • Download File
  • Delete File
  • Get File List
  • Get File Info

Was this helpful?

  1. Swan IPFS Storage
  2. Developer Quickstart
  3. SDK
  4. js MCS SDK

Bucket Storage

Guide to multichain.storage's Bucket Storage

In a multichain storage system, a bucket is a logical container that stores folders or files. Each bucket has a unique name and can contain any number of folders and files. Folders are virtual containers that organize files and help manage data, and files are individual data objects that can be of any type or format.

Create a Bucket

createBucket(bucketName)

require('dotenv').config()
const { mcsSDK } = require('js-mcs-sdk')

async function main() {
  // ENTER PARAMETERS
  const BUCKET_NAME = ''

  const mcs = await mcsSDK.initialize({
    apiKey: process.env.API_KEY,
    accessToken: process.env.ACCESS_TOKEN,
  })
  
  let createBucketResponse = await mcs.createBucket(BUCKET_NAME)
}

main()

Parameters

  • bucketName: The name of the bucket

Return

{ status: 'success', data: <bucket_uid> }

Get Bucket(s)

getBuckets(), getBucketList()

These two functions are actually interchangeable, it will return the list of buckets.

require('dotenv').config()
const { mcsSDK } = require('js-mcs-sdk')

async function main() {
  const mcs = await mcsSDK.initialize({
    accessToken: process.env.ACCESS_TOKEN,
    apiKey: process.env.API_KEY,
  })
  
  let bucketInfo = await mcs.getBuckets()
  console.log(bucketInfo)
}

main()

Return

{
  status: 'success',
  data: [
    {
      bucket_uid: '233...1cd',
      address: '0x1f...4C6',
      max_size: 34359738368,
      size: 0,
      is_free: true,
      payment_tx: '',
      is_active: true,
      is_deleted: false,
      bucket_name: 'test-bucket',
      file_number: -1,
      id: 411,
      created_at: '2023-02-23T20:35:28Z',
      updated_at: '2023-02-23T20:35:28Z',
      deleted_at: null
    }
  ]
}

Delete Bucket

deleteBucket(bucketName)

require('dotenv').config()
const { mcsSDK } = require('js-mcs-sdk')

async function main() {
  // ENTER PARAMETERS
  const BUCKET_NAME = ''

  const mcs = await mcsSDK.initialize({
    apiKey: process.env.API_KEY,
    accessToken: process.env.ACCESS_TOKEN,
  })
  
  let deleteBucketResponse = await mcs.deleteBucket(BUCKET_NAME)
}

main()

Parameters

  • bucketName: The name of the bucket

Return

{ status: 'success' }

Rename Bucket

renameBucket(oldName, newName)

require('dotenv').config()
const { mcsSDK } = require('js-mcs-sdk')

async function main() {
  // ENTER PARAMETERS
  const BUCKET_NAME = ''
  const NEW_BUCKET_NAME = ''

  const mcs = await mcsSDK.initialize({
    apiKey: process.env.API_KEY,
    accessToken: process.env.ACCESS_TOKEN,
  })
  
  let renameResponse = await mcs.renameBucket(BUCKET_NAME, NEW_BUCKET_NAME)
}

main()

Parameters

  • oldName: The name of the bucket

  • newName: The new name of the bucket

Return

{ status: 'success', data: 'rename success' }

Create Folder

createFolder(bucketName, objectName)

require('dotenv').config()
const { mcsSDK } = require('js-mcs-sdk')

async function main() {
  // ENTER PARAMETERS
  const BUCKET_NAME = ''
  const OBJECT_NAME = ''

  const mcs = await mcsSDK.initialize({
    accessToken: process.env.ACCESS_TOKEN,
    apiKey: process.env.API_KEY,
  })
  
  let folderResponse = await mcs.createFolder(BUCKET_NAME, OBJECT_NAME)
  console.log(folderResponse)
}

main()

Parameters

  • bucketName: The name of the bucket

  • objectName: The name of the folder path inside the bucket

Return

{ status: 'success', data: '<folder_name>' }

Upload File

uploadToBucket(bucketName, objectName, filePath, replace=false)

require('dotenv').config()
const { mcsSDK } = require('js-mcs-sdk')

async function main() {
  // ENTER PARAMETERS
  const BUCKET_NAME = ''
  const OBJECT_NAME = ''
  const FILE_PATH = ''

  const mcs = await mcsSDK.initialize({
    accessToken: process.env.ACCESS_TOKEN,
    apiKey: process.env.API_KEY,
  })
  
  let uploadResponse = await mcs.uploadToBucket(BUCKET_NAME, OBJECT_NAME, FILE_PATH)
  console.log(uploadResponse)
}

main()

Parameters

  • bucketName: The name of the bucket

  • objectName: The name of the file path inside the bucket (ex: folder1/folder2/file.png)

  • filePath: The local path to the file (ex: Desktop/images/file.png)

  • replace: Bucket Storage does not allow files of the same name, set replace to true to replace the existing file

Return

{
  status: 'success',
  data: {
    file_id: <file_id>,
    file_hash: '7e...96',
    file_is_exist: false,
    ipfs_is_exist: false,
    size: 63447054,
    payload_cid: 'Qme...kMr',
    ipfs_url: 'https://ipfs.multichain.storage/ipfs/Qm...'
  }
}

Download File

downloadFile(bucketName, objectName, outputPath='.')

Downloads an uploaded file in a bucket, to the desired outputDirectory

require('dotenv').config()
const { mcsSDK } = require('js-mcs-sdk')

async function main() {
  // ENTER PARAMETERS
  const BUCKET_NAME = ''
  const OBJECT_NAME = ''
  const OUTPUT_PATH = '.'

  const mcs = await mcsSDK.initialize({
    accessToken: process.env.ACCESS_TOKEN,
    apiKey: process.env.API_KEY
  })

  let downloadResponse = await mcs.downloadFile(BUCKET_NAME, OBJECT_NAME, OUTPUT_PATH)
}

main()

Parameters

  • bucketName: The name of the bucket

  • objectName: Path of the object you want to download (ex: folder1/folder2/file.png)

  • outputPath: Output path of the downloaded file (default is '.' i.e current directory)

Return

{ status: 'success' }

Delete File

deleteFile(bucketName, objectName)

require('dotenv').config()
const { mcsSDK } = require('js-mcs-sdk')

async function main() {
  // ENTER PARAMETERS
  const BUCKET_NAME = ''
  const OBJECT_NAME = ''

  const mcs = await mcsSDK.initialize({
    accessToken: process.env.ACCESS_TOKEN,
    apiKey: process.env.API_KEY,
  })
  
  let deleteResponse = await mcs.deleteFile(BUCKET_NAME, OBJECT_NAME)
  console.log(deleteResponse)
}

main()

Parameters

  • bucketName: The name of the bucket

  • objectName: The name of the object to delete

Return

{ status: 'success' }

Get File List

getFileList(bucketName, params), getFiles(bucketName, params)

require('dotenv').config()
const { mcsSDK } = require('js-mcs-sdk')

async function main() {
  // ENTER PARAMETERS
  const BUCKET_NAME = ''
  const PARAMS = {
    prefix: '',
    limit: 10,
    offset: 0
  } 

  const mcs = await mcsSDK.initialize({
    apiKey: process.env.API_KEY,
    accessToken: process.env.ACCESS_TOKEN,
  })
  
  let fileList = await mcs.getFileList(BUCKET_NAME, PARAMS)
  console.log(fileList)
}

main()

Parameters

  • bucketName: The name of the bucket

  • params

    • prefix: the folder prefix if you want the list of files in a subfolder

    • limit: number of returned files

    • offset: page number

Return

{
  file_list: [
    {
      name: 'f1',
      address: '0x1...4C6',
      prefix: '',
      bucket_uid: '233...1cd',
      file_hash: '',
      size: 0,
      payload_cid: '',
      ipfs_url: '',
      pin_status: '',
      is_deleted: false,
      is_folder: true,
      object_name: 'f1',
      id: 6548,
      created_at: '2023-02-24T17:33:56Z',
      updated_at: '2023-02-24T17:33:56Z',
      deleted_at: null
    }
    ...
  ],
  count: 1
}

Get File Info

getFileInfo(bucketName, objectName)

require('dotenv').config()
const { mcsSDK } = require('js-mcs-sdk')

async function main() {
  // ENTER PARAMETERS
  const BUCKET_NAME = ''
  const OBJECT_NAME = ''

  const mcs = await mcsSDK.initialize({
    apiKey: process.env.API_KEY,
    accessToken: process.env.ACCESS_TOKEN,
  })
  
  let fileInfo = await mcs.getFileInfo(BUCKET_NAME, OBJECT_NAME)
  console.log(fileInfo)
}

main()

Parameters

  • bucketName: The name of the bucket

  • objectName: The name of the object

Return

{
  status: 'success',
  data: {
    name: '<file_name>',
    address: '0x1ff...4C6',
    prefix: '',
    bucket_uid: '233...1cd',
    file_hash: '',
    size: 0,
    payload_cid: '',
    ipfs_url: '',
    pin_status: '',
    is_deleted: false,
    is_folder: true,
    object_name: '<object_name>',
    id: 6548,
    created_at: '2023-02-24T17:33:56Z',
    updated_at: '2023-02-24T17:33:56Z',
    deleted_at: null
  }
}
PreviousGet StartedNextOnchain Storage

Last updated 2 years ago

Was this helpful?