Optimized image storage
This commit is contained in:
parent
6e0b4f75b7
commit
cc8efee25f
|
@ -60,8 +60,10 @@
|
||||||
var guid = await ImageService.StoreImageAsync(tempFilePath);
|
var guid = await ImageService.StoreImageAsync(tempFilePath);
|
||||||
if (!guid.HasValue) throw new ApplicationException("Processing Image failed.");
|
if (!guid.HasValue) throw new ApplicationException("Processing Image failed.");
|
||||||
|
|
||||||
|
Guid? imageToDelete = null;
|
||||||
await using var context = await ContextFactory.CreateDbContextAsync();
|
await using var context = await ContextFactory.CreateDbContextAsync();
|
||||||
if (User.ProfilePicture is not null) {
|
if (User.ProfilePicture is not null) {
|
||||||
|
imageToDelete = User.ProfilePicture.ImageId;
|
||||||
context.Remove(User.ProfilePicture);
|
context.Remove(User.ProfilePicture);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -72,7 +74,9 @@
|
||||||
context.Update(User);
|
context.Update(User);
|
||||||
await context.SaveChangesAsync();
|
await context.SaveChangesAsync();
|
||||||
|
|
||||||
// TODO notify changed pfp
|
if (imageToDelete is not null)
|
||||||
|
ImageService.Delete(imageToDelete.Value);
|
||||||
|
await InvokeAsync(StateHasChanged);
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
|
@ -30,7 +30,8 @@
|
||||||
try {
|
try {
|
||||||
string tempPath = await FileUtilities.StoreTemporary(args.File.OpenReadStream(MaxFileSize));
|
string tempPath = await FileUtilities.StoreTemporary(args.File.OpenReadStream(MaxFileSize));
|
||||||
await FileUploadedCallback.InvokeAsync(tempPath);
|
await FileUploadedCallback.InvokeAsync(tempPath);
|
||||||
Message = string.Empty;
|
Message = string.Empty;
|
||||||
|
File.Delete(tempPath);
|
||||||
} catch (Exception ex) {
|
} catch (Exception ex) {
|
||||||
Message = "File upload failed: " + ex.Message;
|
Message = "File upload failed: " + ex.Message;
|
||||||
} finally {
|
} finally {
|
||||||
|
|
|
@ -1,4 +1,5 @@
|
||||||
using ImageMagick;
|
using ImageMagick;
|
||||||
|
using static System.Net.Mime.MediaTypeNames;
|
||||||
|
|
||||||
namespace Wave.Services;
|
namespace Wave.Services;
|
||||||
|
|
||||||
|
@ -47,4 +48,9 @@ public class ImageService(ILogger<ImageService> logger) {
|
||||||
return null;
|
return null;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public void Delete(Guid imageId) {
|
||||||
|
string path = Path.Combine(BasePath, imageId + ImageExtension);
|
||||||
|
File.Delete(path);
|
||||||
|
}
|
||||||
}
|
}
|
Loading…
Reference in a new issue