From 940e6f847e61de27c5939634007d3a269b70f934 Mon Sep 17 00:00:00 2001 From: Laura Hausmann Date: Sun, 17 Nov 2024 17:12:19 +0100 Subject: [PATCH] [backend/drive] Fix errors when uploading files with long names containing unicode characters to object storage --- .../Core/Services/ObjectStorageService.cs | 10 +++++++--- 1 file changed, 7 insertions(+), 3 deletions(-) diff --git a/Iceshrimp.Backend/Core/Services/ObjectStorageService.cs b/Iceshrimp.Backend/Core/Services/ObjectStorageService.cs index 0cf5248c..fb5e5399 100644 --- a/Iceshrimp.Backend/Core/Services/ObjectStorageService.cs +++ b/Iceshrimp.Backend/Core/Services/ObjectStorageService.cs @@ -1,5 +1,5 @@ using System.Collections.Immutable; -using System.Net.Mime; +using System.Net.Http.Headers; using System.Text; using Carbon.Storage; using Iceshrimp.Backend.Core.Configuration; @@ -85,9 +85,13 @@ public class ObjectStorageService(IOptions config, HttpCl public async Task UploadFileAsync(string key, string contentType, string filename, Stream data) { if (_bucket == null) throw new Exception("Refusing to upload to object storage with invalid configuration"); - var properties = (_acl ?? BlobProperties.Empty).ToDictionary(); + + var properties = (_acl ?? BlobProperties.Empty).ToDictionary(); + var contentDisposition = new ContentDispositionHeaderValue("inline") { FileName = filename }.ToString(); + properties.Add("Content-Type", contentType); - properties.Add("Content-Disposition", new ContentDisposition("inline") { FileName = filename }.ToString()); + properties.Add("Content-Disposition", contentDisposition); + IBlob blob = data.Length > 0 ? new Blob(GetKeyWithPrefix(key), data, properties) : new EmptyBlob(GetKeyWithPrefix(key), data, properties);