I have the following problem: A java InputStream object is downloaded from an S3 storage and then passed to MinIo. Before I pass the InputStream to MinIo a create a new InputStream (ByteArrayInputStream) from the one I dowloaded from S3. Basically, the aim is to download a zip file which has .zip.p7m extension (signature has been applied) and store it into another storage.
Here is the code:
try (InputStream downloadedFileS3 = s3Service.readFileFromS3(body.getAckPath(), Modalita.ACK)) {
ByteArrayOutputStream buffer = new ByteArrayOutputStream();
byte[] byteArray = new byte[4096];
int length;
while ((length = downloadedFileS3.read(byteArray)) != -1) {
buffer.write(byteArray, 0, length);
}
byte[] bytes = buffer.toByteArray();
// Create a new FileInputStream
InputStream newInputStream = new ByteArrayInputStream(bytes);
//Upload file on MinIo
minIoService.uploadFile(bucketName, completeStorageFileName, newInputStream);
BucketName and completeStorageFileName are given.
Thing is that I found the file on MinIo but I cannot open it as folder. Actually, I am able to open it with 7zip and see the content but I am not able to open it as folder when I chang the extension from .zip.p7m to .zip.
Anyone could please explain why this is happening?
Here is the code of the minio.service.uploadFile method:
public void uploadFile(String bucket, String source, InputStream file) throws MinIoCheckedException {
try {
minioClient.putObject(
PutObjectArgs.builder()
.bucket(bucket)
.object(source)
.contentType("application/octet-stream")
.stream(file, file.available(), -1)
.build());
} catch (Exception e) {
throw new MinIoCheckedException("Errore upload file su minio", e);
}
}
I am sure the file on S3 storage is not corrupted because I can open It correcly…