Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Support using PutObjectAsync return a HttpStatusCode and throw Exception when StatusCode not equal 200 #1171

Open
lengochiep99 opened this issue Sep 4, 2024 · 4 comments

Comments

@lengochiep99
Copy link

PutObjectAsync return a PutObjectResponse, but property HttpStatusCode and ResponseContent is a internal. I checked log, and HttpStatusCode is 400, but cann't access the attribute ResponseStatusCode

@ArminShoeibi
Copy link

ArminShoeibi commented Sep 5, 2024

Yes, we need to change these properties to public

internal string ResponseContent { get; }

internal HttpStatusCode ResponseStatusCode { get; }

@n-goncalves
Copy link

Yes, we need to change these properties to public

internal string ResponseContent { get; }

internal HttpStatusCode ResponseStatusCode { get; }

It's a bit more than that.

Currently the documentation and the samples that are available here or in https://min.io/docs/minio/linux/developers/dotnet/quickstart.html makes one assume that an upload is successful if no exception is triggered.
This is wrong and dangerous since that assumption can make you lose files as I already wrote in #1176.
As the person who opened this issue, we've also seen PutObjectResponse with a non 200 HttpStatusCode, 400 or 500 to be precise.

Example of PutObject documentation taken from README:

try 
{
...
// Upload a file to bucket.
 var putObjectArgs = new PutObjectArgs()
  .WithBucket(bucketName)
  .WithObject(objectName)
 .WithFileName(filePath)
 .WithContentType(contentType);
await minio.PutObjectAsync(putObjectArgs).ConfigureAwait(false);
Console.WriteLine("Successfully uploaded " + objectName );
} 
...

@ArminShoeibi
Copy link

ArminShoeibi commented Nov 1, 2024

Yes, we need to change these properties to public

internal string ResponseContent { get; }

internal HttpStatusCode ResponseStatusCode { get; }

It's a bit more than that.

Currently the documentation and the samples that are available here or in https://min.io/docs/minio/linux/developers/dotnet/quickstart.html makes one assume that an upload is successful if no exception is triggered. This is wrong and dangerous since that assumption can make you lose files as I already wrote in #1176. As the person who opened this issue, we've also seen PutObjectResponse with a non 200 HttpStatusCode, 400 or 500 to be precise.

Example of PutObject documentation taken from README:

try 
{
...
// Upload a file to bucket.
 var putObjectArgs = new PutObjectArgs()
  .WithBucket(bucketName)
  .WithObject(objectName)
 .WithFileName(filePath)
 .WithContentType(contentType);
await minio.PutObjectAsync(putObjectArgs).ConfigureAwait(false);
Console.WriteLine("Successfully uploaded " + objectName );
} 
...

I'm sorry, I didn't get that, Why is it more than publicizing those modifiers?

This merge request is ready and makes those modifiers public
#1195

@n-goncalves
Copy link

Publicizing those modifiers isn't the same as triggering an Exception if the status code isn't 200 which is the title of this issue.

Is it expected that PutObjectAsync doesn't trigger an Exception but still fails to do the upload ?
This is mentioned nowhere in the MinIO .NET Client API Documentation. The only way to know that is to read the code in depth ... or experience it the hard way and lose a file due to this.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants