@cere-ddc-sdk/file-storage
The package provides API for storing and reading large files to DDC
Installation
Using NPM:
npm install @cere-ddc-sdk/file-storage --save
Using yarn:
yarn add @cere-ddc-sdk/file-storage
Usage
A quick guide of how to upload a file to DDC Testnet using the FileStorage API.
@cere-ddc-sdk/file-storage3.0 is ESM-only and requires Node ≥ 22.11. Upgrading from 2.x? See MIGRATION.md — the network presets (TESTNET/DEVNET/MAINNET) are gone, replaced by an explicitstorageUrl.
-
Create a
FileStorageinstanceimport * as fs from 'fs'; import { FileStorage, File } from '@cere-ddc-sdk/file-storage'; const bucketId = 1n; const seed = 'hybrid label reunion only dawn maze asset draft cousin height flock nation'; const fileStorage = await FileStorage.create(seed, { storageUrl: 'https://storage.testnet.cere.network', });storageUrlhandles writes and, unless you also passcdnUrl, reads.FileStorageno longer opens a blockchain connection of its own.The account used to create the instance should have a positive balance, DDC deposit, and the bucket should be created in advance
-
Upload a file to DDC
const filePath = './my-picture.jpg'; const fileStats = fs.statSync(filePath); const fileStream = fs.createReadStream(filePath); const file = new File(fileStream, { size: fileStats.size }); const fileCID = await fileStorage.store(bucketId, file); console.log('The uploaded file CID', fileCID) -
That is it. You can open the file from your browser
const fileUrl = `https://storage.testnet.cere.network/${bucketId}/${fileCID}`; console.log('The file URL', fileUrl);
Documentation
For more information about what this package provides, see API reference
License
Licensed under the Apache License