minio / minio-js

MinIO Client SDK for Javascript
https://docs.min.io/docs/javascript-client-quickstart-guide.html
Apache License 2.0
920 stars 271 forks source link

how to set object Content-Type in composeObject #1304

Open realAndDream opened 2 months ago

realAndDream commented 2 months ago

Hello everyone. I want to upload an mp4 file to minio. I first uploaded the file's fragmented data, and then used composeObject to merge these fragmented files. The objects can be merged into a new object, but its Content-Type is binary/octet-stream. I can't modify the ContentType using UserMetadata. How do I specify this Content-Type? Thanks, the code is following:

async composeFileParts(dto: ComposeFilePartsDto) {
    const stream = this.minioClient.listObjects(dto.bucket, `${dto.md5}_`)
    const data = (await getReadObjectsNamesStreamData(stream)) as [
        {
            name: string
        },
    ]

    const allIndex: number[] = data.map((value) => {
        return parseInt(value.name.substring(value.name.lastIndexOf("_") + 1))
    })
    allIndex.sort((a, b) => (a < b ? -1 : 1))

    const sourceList: minio.CopySourceOptions[] = []
    allIndex.forEach((value) => {
        const source = new minio.CopySourceOptions({
            Bucket: dto.bucket,
            Object: `${dto.md5}_${value}`,
        })
        sourceList.push(source)
    })

    const destOption = new minio.CopyDestinationOptions({
        Bucket: dto.bucket,
        Object: `${dto.md5}.${dto.suffix}`,
        UserMetadata: {
            "Content-Type": "video/mp4",
            test: "test",
        },
        MetadataDirective: "REPLACE",
    })
    await this.minioClient.composeObject(destOption, sourceList)
}