简体   繁体   English

如何从一个minio服务器复制到另一个?

[英]How to copy from one minio server to another?

I am using Minio's JAVA SDK. I managed to copy objects within the same Minio Server.我正在使用 Minio 的 JAVA SDK。我设法在同一个 Minio 服务器中复制对象。 Is there a way to copy the objects from one Minio server to another?有没有办法将对象从一个 Minio 服务器复制到另一个?

I have tried using the below code:我尝试使用以下代码:

InputStream inputStream = minioClientServer1.getObject(getBucket(), fileName);
minioClientServer2.putObject(getBucket(), fileName, inputStream, (long) inputStream.available(), null, null, contentType);

That is I got the object from one server and then uploaded to the next.那是我从一台服务器得到 object 然后上传到下一台。 The problem that I'm facing is that the contentType is unknown.我面临的问题是contentType未知。

Is there a way to do this without hard coding the content type?有没有办法在不对内容类型进行硬编码的情况下做到这一点? Or downloading the object to a file then uploading is a better way?或者将 object 下载到文件然后上传是更好的方法吗?

I'm not sure that this applies to you because you don't provide enough information for me to be sure we're talking about the same SDK. But from what you show, you should be able to call statObject in the same way that you call getObject and get an ObjectStat instance rather than an InputStream instance for a particular S3 object. Once you have an ObjectStat instance, you should be able to call the contentType method on it to get the content type of the S3 object.我不确定这是否适用于你,因为你没有提供足够的信息让我确定我们谈论的是同一个statObject但是从你展示的内容来看,你应该能够以与您调用getObject并获取特定 S3 object 的ObjectStat实例而不是InputStream实例。一旦您拥有ObjectStat实例,您应该能够对其调用contentType方法以获取 S3 object 的内容类型。

This should work to do what you're asking:这应该可以满足您的要求:

ObjectStat objectStat = minioClientServer1.statObject(getBucket(), fileName);
InputStream inputStream = minioClientServer1.getObject(getBucket(), fileName);
minioClientServer2.putObject(getBucket(), fileName, inputStream, (long) inputStream.available(), null, null, objectStat.contentType());

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM