minio / minio-java

MinIO Client SDK for Java
https://docs.min.io/docs/java-client-quickstart-guide.html
Apache License 2.0
1.12k stars 484 forks source link

How to set object Content-Type in composeObject #1574

Closed zqr95518 closed 4 months ago

zqr95518 commented 4 months ago

https://github.com/minio/minio-js/issues/1304#issue-2342833209 Have the same problem. When I composeObject contentType become application/octet-stream.

        <dependency>
            <groupId>io.minio</groupId>
            <artifactId>minio</artifactId>
            <version>8.5.11</version>
        </dependency>

PutObject with contentType

            ObjectWriteResponse objectWriteResponse = MinioService.minioClient.putObject(
                    PutObjectArgs.builder()
                            .bucket(bucket)
                            .object(md5.concat("/").concat(Integer.toString(sliceIndex)))
                            .stream(inputStream, available, -1)
                            .contentType(contentType)
                            .build());

Can't set contentType use composeObject

        List<ComposeSource> sourceObjectList = Stream.iterate(0, i -> ++i)
                .limit(totalPieces)
                .map(i -> ComposeSource.builder()
                        .bucket(entity.getBucketName())
                        .object(md5.concat("/").concat(Integer.toString(i)))
                        .build())
                .toList();
        ObjectWriteResponse objectWriteResponse = MinioService.minioClient.composeObject(
                ComposeObjectArgs.builder()
                        .bucket(entity.getBucketName())
                        .object(entity.getObjectName())
                        .sources(sourceObjectList)
                        .build()
        );
balamurugana commented 4 months ago

Use extraHeaders argument

zqr95518 commented 4 months ago

Use extraHeaders argument

Can I have a example?

zqr95518 commented 4 months ago

Use extraHeaders argument

Can I have a example?

I try this and solve the problem. Thanks.

        Multimap<String, String> extraHeaders = HashMultimap.create();
        extraHeaders.put("Content-Type", entity.getContentType());
        ObjectWriteResponse objectWriteResponse = MinioService.minioClient.composeObject(
                ComposeObjectArgs.builder()
                        .bucket(entity.getBucketName())
                        .object(entity.getObjectName())
                        .headers(extraHeaders)
                        .sources(sourceObjectList)
                        .build()