将unit8array转换为“ stream.Readable”或“ Buffer”或“ string”

问题描述

我正在尝试从视频帧中提取图像,然后导出到s3存储库min.io(https://docs.min.io/docs/javascript-client-api-reference.html

使用putObject将图像写入s3存储桶时,第三个参数“ content”必须为buffer / stream.read / string。但是,从代码1中,我获得了“ content”作为unit8array。我看着这个(Uint8Array to image in javascript),但似乎不适用于我的情况。欢迎任何提示!

代码1: 这是从视频中提取图像的代码:

 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,canvas.width,canvas.height);
            canvas.toBlob(resolve,"image/jpeg",1.0); // inside which it calls writeBinary
        };

代码2:这是将图像写入min.io s3存储桶的代码,其基本内容应为流/缓冲区。

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);
    });
}

错误: 未处理的拒绝(TypeError):第三个参数的类型应为“ stream.Readable”或“ Buffer”或“ string”

16 |     secrect?: string;

17 | } 18 |

19 |导出类MinioStorage实现IStorageProvider { 20 | / ** 21 | *储存类型 22 | * @returns-StorageType.Cloud

16 | secret ?:字符串; 17 | } 18 |

19 |导出类MinioStorage实现IStorageProvider { 20 | / ** 21 | *储存类型 22 | * @returns-StorageType.Cloud

解决方法

暂无找到可以解决该程序问题的有效方法,小编努力寻找整理中!

如果你已经找到好的解决方法,欢迎将解决方案带上本链接一起发送给小编。

小编邮箱:dio#foxmail.com (将#修改为@)