minio-dotnet icon indicating copy to clipboard operation
minio-dotnet copied to clipboard

Issue with File Not Being Released After PutObjectAsync Upload

Open sunny1028 opened this issue 2 years ago • 4 comments

🐞 Issue: Local file remains locked after successful PutObjectAsync upload I'm using the MinIO .NET SDK to upload a file using PutObjectAsync. The upload completes successfully — I can see the file in the MinIO web console — but afterward, the local file stays locked and cannot be deleted.

Even after waiting for one minute, attempting to delete the file results in an IOException indicating that the file is being used by another process.

🔁 Reproducible Code

if (!File.Exists(filePath))
{
    Console.WriteLine($"file does not exist! [{filePath}]");
    return;
}

var client = new MinioClient()
    .WithEndpoint(endpoint)
    .WithTimeout((int)TimeSpan.FromSeconds(5).TotalMilliseconds)
    .WithCredentials(accessKey, secretKey)
    .Build();

await client.PutObjectAsync(new PutObjectArgs()
    .WithBucket("xys-patent-file")
    .WithObject($"temp/test/{Path.GetFileName(filePath)}")
    .WithFileName(filePath));

Console.WriteLine("success!");
Thread.Sleep(TimeSpan.FromMinutes(1));

// This throws:
// System.IO.IOException: The process cannot access the file because it is being used by another process.
File.Delete(filePath);

✅ Environment MinIO .NET SDK version: (e.g., v5.0.0)

🧐 What I’ve verified The file exists and is not in use by any other process before upload.

The upload succeeds without any error.

The file remains locked after upload, even after a delay.

❓Question Is this a known issue in the SDK? Do I need to manually dispose something after using PutObjectAsync? How can I release the lock so I can safely delete the local file?

Any help would be appreciated!

sunny1028 avatar Sep 27 '23 05:09 sunny1028

I have that exact same issue, did you find a solution ?

Noulens avatar May 23 '24 14:05 Noulens

I'm using Minio version 4.0.0. Use stream to solve the problem

var bytes = File.ReadAllBytes(path);
using var stream = new MemoryStream(bytes);
.....

HZ-GeLiang avatar Aug 02 '24 08:08 HZ-GeLiang

Yes thanks a lot, stream does it

Noulens avatar Aug 02 '24 18:08 Noulens