diff --git a/Iceshrimp.Backend/Core/Services/DriveService.cs b/Iceshrimp.Backend/Core/Services/DriveService.cs index 5fbb3665..8ccd0444 100644 --- a/Iceshrimp.Backend/Core/Services/DriveService.cs +++ b/Iceshrimp.Backend/Core/Services/DriveService.cs @@ -216,7 +216,7 @@ public class DriveService( else { data.Seek(0, SeekOrigin.Begin); - await storageSvc.UploadFileAsync(filename, data); + await storageSvc.UploadFileAsync(filename, request.MimeType, data); url = storageSvc.GetFilePublicUrl(filename).AbsoluteUri; if (thumbnailFilename != null && res?.RenderThumbnail != null) @@ -226,7 +226,7 @@ public class DriveService( await using var stream = new MemoryStream(); await res.RenderThumbnail(stream); stream.Seek(0, SeekOrigin.Begin); - await storageSvc.UploadFileAsync(thumbnailFilename, stream); + await storageSvc.UploadFileAsync(thumbnailFilename, "image/webp", stream); thumbnailUrl = storageSvc.GetFilePublicUrl(thumbnailFilename).AbsoluteUri; } catch (Exception e) @@ -242,7 +242,7 @@ public class DriveService( await using var stream = new MemoryStream(); await res.RenderWebpublic(stream); stream.Seek(0, SeekOrigin.Begin); - await storageSvc.UploadFileAsync(webpublicFilename, stream); + await storageSvc.UploadFileAsync(webpublicFilename, "image/webp", stream); webpublicUrl = storageSvc.GetFilePublicUrl(webpublicFilename).AbsoluteUri; } catch (Exception e) @@ -267,7 +267,7 @@ public class DriveService( else { data.Seek(0, SeekOrigin.Begin); - await storageSvc.UploadFileAsync(filename, data); + await storageSvc.UploadFileAsync(filename, request.MimeType, data); url = storageSvc.GetFilePublicUrl(filename).AbsoluteUri; } } diff --git a/Iceshrimp.Backend/Core/Services/ObjectStorageService.cs b/Iceshrimp.Backend/Core/Services/ObjectStorageService.cs index 53d2f320..4031781b 100644 --- a/Iceshrimp.Backend/Core/Services/ObjectStorageService.cs +++ b/Iceshrimp.Backend/Core/Services/ObjectStorageService.cs @@ -61,7 +61,7 @@ public class ObjectStorageService(IOptions config, HttpCl const string filename = ".iceshrimp-test"; var content = CryptographyHelpers.GenerateRandomString(16); - await UploadFileAsync(filename, Encoding.UTF8.GetBytes(content)); + await UploadFileAsync(filename, "text/plain", Encoding.UTF8.GetBytes(content)); string result; try @@ -78,12 +78,15 @@ public class ObjectStorageService(IOptions config, HttpCl throw new Exception("Failed to verify access url (content mismatch)"); } - private Task UploadFileAsync(string filename, byte[] data) => UploadFileAsync(filename, new MemoryStream(data)); + private Task UploadFileAsync(string filename, string contentType, byte[] data) => + UploadFileAsync(filename, contentType, new MemoryStream(data)); - public async Task UploadFileAsync(string filename, Stream data) + public async Task UploadFileAsync(string filename, string contentType, Stream data) { if (_bucket == null) throw new Exception("Refusing to upload to object storage with invalid configuration"); - var blob = new Blob(GetFilenameWithPrefix(filename), data, _acl ?? BlobProperties.Empty); + var properties = (_acl ?? BlobProperties.Empty).ToDictionary(); + properties.Add("Content-Type", contentType); + var blob = new Blob(GetFilenameWithPrefix(filename), data, properties); await _bucket.PutAsync(blob); } diff --git a/Iceshrimp.Backend/Core/Services/StorageMaintenanceService.cs b/Iceshrimp.Backend/Core/Services/StorageMaintenanceService.cs index 8c77b380..c0c9ac13 100644 --- a/Iceshrimp.Backend/Core/Services/StorageMaintenanceService.cs +++ b/Iceshrimp.Backend/Core/Services/StorageMaintenanceService.cs @@ -55,7 +55,7 @@ public class StorageMaintenanceService( var path = Path.Join(pathBase, file.AccessKey); var stream = File.OpenRead(path); - await objectStorageSvc.UploadFileAsync(file.AccessKey, stream); + await objectStorageSvc.UploadFileAsync(file.AccessKey, file.Type, stream); file.Url = objectStorageSvc.GetFilePublicUrl(file.AccessKey).AbsoluteUri; pathsToDelete.Add(path); } @@ -65,7 +65,7 @@ public class StorageMaintenanceService( var path = Path.Join(pathBase, file.ThumbnailAccessKey); var stream = File.OpenRead(path); - await objectStorageSvc.UploadFileAsync(file.ThumbnailAccessKey, stream); + await objectStorageSvc.UploadFileAsync(file.ThumbnailAccessKey, "image/webp", stream); file.ThumbnailUrl = objectStorageSvc.GetFilePublicUrl(file.ThumbnailAccessKey).AbsoluteUri; pathsToDelete.Add(path); } @@ -75,7 +75,7 @@ public class StorageMaintenanceService( var path = Path.Join(pathBase, file.WebpublicAccessKey); var stream = File.OpenRead(path); - await objectStorageSvc.UploadFileAsync(file.WebpublicAccessKey, stream); + await objectStorageSvc.UploadFileAsync(file.WebpublicAccessKey, "image/webp", stream); file.WebpublicUrl = objectStorageSvc.GetFilePublicUrl(file.WebpublicAccessKey).AbsoluteUri; pathsToDelete.Add(path); }