minio / minio-dotnet

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

Status code in `PutObjectResponse` is internal, unlike AWS S3's implementation #1176

Open minhaz109074 opened 2 months ago

minhaz109074 commented 2 months ago

Description:

In the MinIO .NET SDK, I encountered an issue where the HttpStatusCode in the PutObjectResponse is internal, making it inaccessible after receiving a response. However, in AWS S3's SDK, the same property is public, which allows developers to easily access the status code of the operation.

Code:

Here’s an example of how the MinIO SDK currently handles the HttpStatusCode:

public class GenericResponse
{
    internal GenericResponse(HttpStatusCode statusCode, string responseContent)
    {
        ResponseContent = responseContent;
        ResponseStatusCode = statusCode;
    }

    internal string ResponseContent { get; }
    internal HttpStatusCode ResponseStatusCode { get; }
}

public class PutObjectResponse : GenericResponse
{
}

Suggestion:

Please consider changing the visibility of ResponseStatusCode from internal to public to align with the behavior of AWS S3's SDK and improve usability.

Environment:

harshavardhana commented 2 months ago

Open SDK issues on relevant repos.

n-goncalves commented 1 month ago

Would be really nice if https://github.com/minio/minio-dotnet/pull/1195 would be merged and released soon given how small of a change it is and how much of an inconvenience it can be (#1176). In our own case, we ended up losing some files sent to a S3 compatible storage due to assuming that if no exception was thrown the upload must have been successful.

It is currently, to my knowledge impossible to detect those kind of issues if you don't access the internal values using Reflection.

Here's how you can do it for the time being:

...
var putObjectResponse = await client.PutObjectAsync(args);
var putObjectResponseType = putObjectResponse.GetType();
var httpStatusCode = (System.Net.HttpStatusCode) putObjectResponseType.GetProperty(
        "ResponseStatusCode", 
        System.Reflection.BindingFlags.NonPublic | 
        System.Reflection.BindingFlags.Instance
    )
 .GetValue(putObjectResponse);
var responseContent = (string) putObjectResponseType.GetProperty(
     "ResponseContent", 
    Reflection.BindingFlags.NonPublic | 
    Reflection.BindingFlags.Instance
)
.GetValue(putObjectResponse);