【问题标题】:Is it possible to save a group of files with MinIO client in one transaction?是否可以在一个事务中使用 MinIO 客户端保存一组文件?
【发布时间】:2021-08-02 21:41:39
【问题描述】:

我有一个将文件存储在 MinIO 服务器上的 Spring Boot 应用程序。我的应用程序接收文件组,应该保存每个组的所有文件,或者在问题组中不保存任何文件。我为组中的每个文件使用io.minio.MinioClient#putObject。现在我的代码看起来像

fun saveFile(folderName: String, fileName: String, file: ByteArray) {
    file.inputStream().use {
        minioClient.putObject(folderName, fileName, it, PutObjectOptions(file.size.toLong(), -1))
    }
}

fun saveFiles(folderName: String, files: Map<String, ByteArray>) {
    try {
        files.forEach { (fileName, file) -> saveFile(folderName, fileName, file) }
    } catch (e: Exception) {
        files.forEach { (fileName, _) -> minioClient.removeObject(folderName, fileName) }
        throw e
    }
}

我想知道如何重构我的 saveFiles 方法以使其更具事务性。

注意没有关于按组读取文件的规则 - 每个文件都可以单独读取。

【问题讨论】:

    标签: spring-boot kotlin transactions inputstream minio


    【解决方案1】:

    你可以试试这个S3 featureMinIO也支持这个功能。

    创建 .tar 或 .zip 存档并使用元数据选项snowball-auto-extract=true(标题:X-Amz-Meta-Snowball-Auto-Extract)发送到 S3,存档将在 S3 中自动提取。

    这不是交易,但对我来说非常相似。

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2015-02-11
      • 2012-07-29
      • 1970-01-01
      • 2023-02-26
      • 2020-09-24
      • 1970-01-01
      相关资源
      最近更新 更多