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

We don't need to validate objectSize

Open haiduong87 opened this issue 2 years ago • 1 comments

I encounter a new issue when upgrading to latest version. And I found this: https://github.com/minio/minio-dotnet/blob/master/Minio/DataModel/ObjectOperationsArgs.cs#L1765

internal override void Validate()
{
    base.Validate();
    // Check atleast one of filename or stream are initialized
    if (string.IsNullOrWhiteSpace(FileName) && ObjectStreamData == null)
        throw new ArgumentException("One of " + nameof(FileName) + " or " + nameof(ObjectStreamData) +
                                    " must be set.");
    if (PartNumber < 0)
        throw new ArgumentOutOfRangeException(nameof(PartNumber), PartNumber,
            "Invalid Part number value. Cannot be less than 0");
    // Check if only one of filename or stream are initialized
    if (!string.IsNullOrWhiteSpace(FileName) && ObjectStreamData != null)
        throw new ArgumentException("Only one of " + nameof(FileName) + " or " + nameof(ObjectStreamData) +
                                    " should be set.");
    if (!string.IsNullOrWhiteSpace(FileName)) utils.ValidateFile(FileName);
    // Check object size when using stream data
    if (ObjectStreamData != null && ObjectSize == 0)
        throw new ArgumentException($"{nameof(ObjectSize)} must be set");
    Populate();
}

private void Populate()
{
    if (!string.IsNullOrWhiteSpace(FileName))
    {
        var fileInfo = new FileInfo(FileName);
        ObjectSize = fileInfo.Length;
        ObjectStreamData = new FileStream(FileName, FileMode.Open, FileAccess.Read);
    }
}

I think we don't need to validate objectSize.

Thanks,

Duong Nguyen

haiduong87 avatar Jun 24 '22 18:06 haiduong87

I create https://github.com/minio/minio-dotnet/pull/655

haiduong87 avatar Jun 24 '22 18:06 haiduong87