Skip to content

How to Retrieve Cid from AWS S3 Response Header When Uploading to BTFS-Compatible

0

Hello AWS Community,

I’m working on a project where I’m uploading files to a BTFS (BitTorrent File System) server using the AWS S3 SDK with an S3-compatible endpoint provided by BTFS. After successfully uploading a file, I need to retrieve the CID (Content Identifier) directly from the response headers, as this CID is essential for accessing the file in the BTFS network.

Here's the approach I’ve tried so far:

Configuring AWS.S3 with my BTFS-compatible endpoint, along with accessKeyId, secretAccessKey, s3ForcePathStyle, and signatureVersion: 'v4'. Attempting to retrieve the CID from the ETag header, but this doesn’t appear to be the actual CID required by BTFS. Setting up a httpUploadProgress listener to check for relevant details, but this only provides progress metrics.

any help here, would be appreciated.

My Code :

const s3 = new S3Client({
  endpoint: "http://127.0.0.1:6001/",
  credentials: {
    accessKeyId: "82f87bd29-9aa5-492e-b479-2afc7bb73fe6", 
    secretAccessKey: "WGicMAdP6fWE9syQi1mL4utpQI3NZwpqs"
  },
  forcePathStyle: true,
  apiVersion: "v4",
  region: "us-east-1"
});

try {
        const response = await s3.send(new PutObjectCommand(params));
        console.log(await response);
      } catch (caught) {
        if (
          caught instanceof S3ServiceException &&
          caught.name === "EntityTooLarge"
        ) {
          console.error(
            `Error from S3 while uploading object to ${bucketName}. \
    The object was too large. To upload objects larger than 5GB, use the S3 console (160GB max) \
    or the multipart upload API (5TB max).`
          );
        } else if (caught instanceof S3ServiceException) {
          console.error(
            `Error from S3 while uploading object to ${bucketName}.  ${caught.name}: ${caught.message}`
          );
        } else {
          throw caught;
        }
      }

response after the file upload

thanks !

1 Answer
0

anyone please help with this issue... !

answered 2 years ago

You are not logged in. Log in to post an answer.

A good answer clearly answers the question and provides constructive feedback and encourages professional growth in the question asker.