Enhance image upload handling and update UI elements for clarity

This commit is contained in:
CodeDevMLH
2026-03-10 01:27:46 +01:00
parent 0cd64d4eea
commit dd07c452ca
2 changed files with 19 additions and 13 deletions

View File

@@ -97,13 +97,19 @@ namespace Jellyfin.Plugin.MediaBarEnhanced.Api
string targetPath = existingFiles[0];
// Read the file and return as a generic octet stream.
// We use FileShare.ReadWrite so that if someone is currently overwriting the file (uploading), we don't block them,
// and we also don't get blocked by other readers.
var stream = new FileStream(targetPath, FileMode.Open, FileAccess.Read, FileShare.ReadWrite);
// Read the file and return with appropriate MIME type
// We use FileShare.ReadWrite | FileShare.Delete so that if someone is currently overwriting the file (uploading), we don't block them.
var stream = new FileStream(targetPath, FileMode.Open, FileAccess.Read, FileShare.ReadWrite | FileShare.Delete);
// "image/*" works reliably as browsers will sniff the exact image mime type (jpeg, png, webp).
return File(stream, "image/*");
string mimeType = "application/octet-stream";
string ext = Path.GetExtension(targetPath).ToLowerInvariant();
switch (ext) {
case ".jpg": case ".jpeg": mimeType = "image/jpeg"; break;
case ".png": mimeType = "image/png"; break;
case ".gif": mimeType = "image/gif"; break;
case ".webp": mimeType = "image/webp"; break;
}
return File(stream, mimeType);
}
/// <summary>