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

Unable to create an object and upload in DCeller #576

Open
devhimanshuhc opened this issue Dec 17, 2024 · 4 comments
Open

Unable to create an object and upload in DCeller #576

devhimanshuhc opened this issue Dec 17, 2024 · 4 comments

Comments

@devhimanshuhc
Copy link

devhimanshuhc commented Dec 17, 2024

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

@ybgbob
Copy link
Contributor

ybgbob commented Dec 18, 2024

  1. Please provide the version of @bnb-chain/reed-solomon
  2. Verify that tempFilePath does have a file generated
  3. Please provide the complete code file if it is convenient

@devhimanshuhc
Copy link
Author

devhimanshuhc commented Dec 18, 2024

@ybgbob

  1. the version:
    "@bnb-chain/greenfield-js-sdk": "^2.2.0",
    "@bnb-chain/reed-solomon": "^1.1.3",
  1. Yes, the file being generated, even getting the file size as 1740 bytes
  2. This is the whole code, before that i just have create bucket function which is working correctly. Please tell what you require, i will share it.

@rrr523
Copy link
Collaborator

rrr523 commented Dec 21, 2024

@devhimanshuhc

The code looks correct.

We now recommend using delegateUploadObject. example

@devhimanshuhc
Copy link
Author

@rrr523 you guys really need to cross-check you sdk examples,i still remember using the sdk a year back and just because of the sdk issues i dropped the idea of using greenfield sdk. and again, as the replies were late, i dropped using the sdk.

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

No branches or pull requests

3 participants