Browse Source

Added validation to image download

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

7
CoviDok/BLL/Storage/StorageHandler.cs

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

25
CoviDok/Controllers/ImagesController.cs

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

Loading…
Cancel
Save