minio / minio-dotnet

MinIO Client SDK for .NET
https://docs.min.io/docs/dotnet-client-quickstart-guide.html
Apache License 2.0
575 stars 230 forks source link

PutObjectAsync ResponseStatusCode always 0 #1204

Open xXAvoraXx opened 2 weeks ago

xXAvoraXx commented 2 weeks ago

I can't find out what I'm doing wrong because it doesn't throw any errors. I am trying to send the file from IFormFile to minio as below, but when I go into minio I see that the file is not loaded. Minio is installed with default settings as docker-compose with one empty bucket and access keys defined.

BucketExistsAsync returns 'true'. There is no problem with the api key.

Version: .NET 6.0 Minio SDK: 6.0.3

                using var fileStream = person.Avatar.OpenReadStream();

                try
                {
                    bool found = await _minioClient.BucketExistsAsync(new BucketExistsArgs().WithBucket("my-bucket"));

                    Aes aesEncryption = Aes.Create();
                    aesEncryption.KeySize = 256;
                    aesEncryption.GenerateKey();
                    var ssec = new SSEC(aesEncryption.Key);

                    var putObjectArgs = new PutObjectArgs()
                        .WithBucket("my-bucket")
                        .WithObject("/businesses/" + businessId + "/people/" + person.Avatar.FileName)
                        .WithStreamData(fileStream)
                        .WithObjectSize(person.Avatar.Length)
                        .WithContentType("application/octet-stream");

                    var response = await _minioClient.PutObjectAsync(putObjectArgs);
                    Console.WriteLine("uploaded successfully");

                    StatObjectArgs statObjectArgs = new StatObjectArgs()
                        .WithBucket("my-bucket")
                        .WithObject("/businesses/" + businessId + "/people/" + person.Avatar.FileName);

                    ObjectStat objectStat = await _minioClient.StatObjectAsync(statObjectArgs);
                    Console.WriteLine(objectStat);
                }
                catch (MinioException e)
                {
                    Console.WriteLine("Error occurred: " + e);
                }