greenfield-js-sdk
greenfield-js-sdk copied to clipboard
Unable to create an object and upload in DCeller
SDK version:^2.2.0
Environment:
- OS (e.g. from /etc/os-release):Windows 11
- Install tools:Nodejs project
What happened: i am trying to to create an object and upload in my greenfield dceller, i followed the example code for nodejs from your github(greenfield_sdk), but i am facing an issue while creating an object. the file is a json file.
What you expected to happen: To upload a file in dceller
Have you tried the latest version: yes
Logs (paste a small part showing an error (< 10 lines) or link a pastebin, gist, etc. containing more of the log file):
C:\FILE_DIRECTORY\node_modules\@bnb-chain\reed-solomon\dist\utils.js:20
const arr = uint8arr.reduce((a, b) => {
^
TypeError: Reduce of empty array with no initial value
at Array.reduce (<anonymous>)
at Object.getIntegrityUint8Array (C:\FILE_DIRECTORY\node_modules\@bnb-chain\reed-solomon\dist\utils.js:20:24)
at NodeAdapterReedSolomon.getChecksumsByEncodeShards (C:\FILE_DIRECTORY\node_modules\@bnb-chain\reed-solomon\dist\index.js:5155:42)
at Worker.<anonymous> (C:\FILE_DIRECTORY\node_modules\@bnb-chain\reed-solomon\dist\node.adapter.js:39:28)
at Worker.emit (node:events:519:28)
at [kOnExit] (node:internal/worker:315:10)
at Worker.<computed>.onexit (node:internal/worker:229:20)
Config (you can paste only the changes you've made):
async createObject(fileName, content) {
console.log(`Starting upload for ${fileName}`);
// Write content to file
const tempDir = path.resolve("./temp");
if (!fs.existsSync(tempDir)) {
fs.mkdirSync(tempDir, { recursive: true });
}
tempFilePath = path.join(tempDir, fileName);
// Ensure content is properly stringified
const contentString =
typeof content === "string" ? content : JSON.stringify(content);
fs.writeFileSync(tempFilePath, contentString, "utf8");
const fileBuffer = fs.readFileSync(tempFilePath);
console.log(`File size: ${fileBuffer.byteLength} bytes`);
// Generate checksums
console.log("Generating checksums...");
const rs = new NodeAdapterReedSolomon();
const expectCheckSums = await rs.encodeInWorker(
__filename, // Use current file
Uint8Array.from(fileBuffer)
);
console.log("Checksums generated successfully");
// Create object transaction
console.log("Creating object transaction...");
const createObjectTx = await this.client.object.createObject({
bucketName: this.bucketName,
objectName: fileName,
creator: process.env.ACCOUNT_ADDRESS,
visibility: VisibilityType.VISIBILITY_TYPE_PUBLIC_READ,
contentType: "application/json",
redundancyType: RedundancyType.REDUNDANCY_EC_TYPE,
payloadSize: Long.fromInt(fileBuffer.byteLength),
expectChecksums: expectCheckSums.map((x) => bytesFromBase64(x)),
});
//further code
Anything else we need to know: idk why am i gettimg this error even i am able buffer size of the file