Browse Source

Added validation to image download

master
Daniel Gyulai 4 years ago
parent
commit
30505154b6
  1. 5
      CoviDok/BLL/Storage/StorageHandler.cs
  2. 11
      CoviDok/Controllers/ImagesController.cs

5
CoviDok/BLL/Storage/StorageHandler.cs

@ -40,9 +40,14 @@ namespace CoviDok.BLL.Storage
} }
public async Task GetImage(string bucketName, string ImageId, Action<Stream> callback) public async Task GetImage(string bucketName, string ImageId, Action<Stream> callback)
{
if (await storageProvider.ObjectExists(bucketName, ImageId))
{ {
await storageProvider.Download(bucketName, ImageId, callback); await storageProvider.Download(bucketName, ImageId, callback);
} }
else throw new KeyNotFoundException();
}
public async Task<bool> ImageExists(string bucketName, string ImageId) public async Task<bool> ImageExists(string bucketName, string ImageId)
{ {

11
CoviDok/Controllers/ImagesController.cs

@ -67,8 +67,8 @@ namespace CoviDok.Controllers
response.Body["reason"] = "unauthorized"; response.Body["reason"] = "unauthorized";
return response; return response;
} }
try {
string res = null; ; string res = null;
await MinioHandler.GetImage(BucketName, imageGet.ImageId, (stream) => { await MinioHandler.GetImage(BucketName, imageGet.ImageId, (stream) => {
StreamReader reader = new StreamReader(stream); StreamReader reader = new StreamReader(stream);
res = reader.ReadToEnd(); res = reader.ReadToEnd();
@ -77,5 +77,12 @@ namespace CoviDok.Controllers
response.Body["image"] = res; response.Body["image"] = res;
return response; return response;
} }
catch (KeyNotFoundException)
{
response.Status = Status.Error;
response.Body["reason"] = "Image not found!";
return response;
}
}
} }
} }

Loading…
Cancel
Save