Convert unit8array to "stream.Readable" or "Buffer" or "string"

662 Views Asked by At

I am trying to extract image from video frames, then export to s3 storage min.io (https://docs.min.io/docs/javascript-client-api-reference.html)

When writing the image to the s3 bucket using putObject, the 3rd argument "content" needs to be buffer / stream.readable / string. However from code 1, I got "content" as unit8array. I looked at this (Uint8Array to image in javascript), but seems not working for my case. Any hints are welcome!

Code 1: This is the code to extract image from video:

 if (!video) {
            video = document.createElement("video");
            video.setAttribute("crossOrigin", "anonymous");

            if (cachingEnabled) {
                this.videoAssetFiles[asset.parent.name] = video;
                refresh = true;
            }
        }

        video.onloadedmetadata = () => {
            video.currentTime = asset.timestamp;
        };
        video.onseeked = () => {
            const canvas = document.createElement("canvas");
            canvas.height = video.videoHeight;
            canvas.width = video.videoWidth;
            const ctx = canvas.getContext("2d");
            ctx.drawImage(video, 0, 0, canvas.width, canvas.height);
            canvas.toBlob(resolve, "image/jpeg", 1.0); // inside which it calls writeBinary
        };

Code 2: This is the code to write the image to min.io s3 bucket, the arugment content supposed to be stream/buffer.

public async writeBinary(blobName: string, content: Buffer) {
    const bucketName = this.options.folderName;

    await minioClient.putObject(bucketName, blobName, content, function(
        err: string,
        etag: string
    ) {
        return console.log(`"${bucketName} ${blobName}: "`, err, etag);
    });
}

Error: Unhandled Rejection (TypeError): third argument should be of type "stream.Readable" or "Buffer" or "string"

16 |     secrect?: string;

17 | } 18 |

19 | export class MinioStorage implements IStorageProvider { 20 | /** 21 | * Storage type 22 | * @returns - StorageType.Cloud

16 | secrect?: string; 17 | } 18 |

19 | export class MinioStorage implements IStorageProvider { 20 | /** 21 | * Storage type 22 | * @returns - StorageType.Cloud

0

There are 0 best solutions below