[backend/drive] Fix errors when uploading files with long names containing unicode characters to object storage

This commit is contained in:
Laura Hausmann 2024-11-17 17:12:19 +01:00
parent 2ef78e3f41
commit 940e6f847e
No known key found for this signature in database
GPG key ID: D044E84C5BE01605

View file

@ -1,5 +1,5 @@
using System.Collections.Immutable; using System.Collections.Immutable;
using System.Net.Mime; using System.Net.Http.Headers;
using System.Text; using System.Text;
using Carbon.Storage; using Carbon.Storage;
using Iceshrimp.Backend.Core.Configuration; using Iceshrimp.Backend.Core.Configuration;
@ -85,9 +85,13 @@ public class ObjectStorageService(IOptions<Config.StorageSection> config, HttpCl
public async Task UploadFileAsync(string key, string contentType, string filename, Stream data) 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"); 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-Type", contentType);
properties.Add("Content-Disposition", new ContentDisposition("inline") { FileName = filename }.ToString()); properties.Add("Content-Disposition", contentDisposition);
IBlob blob = data.Length > 0 IBlob blob = data.Length > 0
? new Blob(GetKeyWithPrefix(key), data, properties) ? new Blob(GetKeyWithPrefix(key), data, properties)
: new EmptyBlob(GetKeyWithPrefix(key), data, properties); : new EmptyBlob(GetKeyWithPrefix(key), data, properties);