ibm-cos-sdk putObject does not create the correct Binary Object

168 Views Asked by At

Following the instructions from the documentation, I try to upload a file on a bucket.

If I upload a text file (i.e. a csv file), everything works as expected.

If I upload a binary string file (i.e. a pdf file) (read using readAsBinaryString), the file on cloud storage is wrong, only blank pages. The file size and the 256hash of the file changes.

enter image description here

I used all:

  1. A buffer Buffer.from(binaryString)
  2. A Uint8Array new TextEncoder().encode(binaryString)
  3. A the binary string

on

putObject({
    Bucket: 'test-b',
    Key: key,
    Body: binaryString
})
1

There are 1 best solutions below

0
On

Instead of using the binary stream of the file for PDF try to upload using the multipart file upload option to upload it.