diff --git a/src/Foundatio.Minio/Storage/MinioFileStorage.cs b/src/Foundatio.Minio/Storage/MinioFileStorage.cs index 9cf39f2..d41e448 100644 --- a/src/Foundatio.Minio/Storage/MinioFileStorage.cs +++ b/src/Foundatio.Minio/Storage/MinioFileStorage.cs @@ -108,6 +108,9 @@ public async Task GetFileInfoAsync(string path) try { var metadata = await _client.StatObjectAsync(new StatObjectArgs().WithBucket(_bucket).WithObject(normalizedPath)).AnyContext(); + if (metadata.ExtraHeaders.TryGetValue("X-Minio-Error-Code", out string errorCode) && (String.Equals(errorCode, "NoSuchBucket") || String.Equals(errorCode, "NoSuchKey"))) + return null; + return new FileSpec { Path = normalizedPath, @@ -135,7 +138,11 @@ public async Task ExistsAsync(string path) try { - return await _client.StatObjectAsync(new StatObjectArgs().WithBucket(_bucket).WithObject(normalizedPath)).AnyContext() != null; + var metadata = await _client.StatObjectAsync(new StatObjectArgs().WithBucket(_bucket).WithObject(normalizedPath)).AnyContext(); + if (metadata.ExtraHeaders.TryGetValue("X-Minio-Error-Code", out string errorCode) && (String.Equals(errorCode, "NoSuchBucket") || String.Equals(errorCode, "NoSuchKey"))) + return false; + + return true; } catch (Exception ex) when (ex is ObjectNotFoundException or BucketNotFoundException) {