feat(media): Add path_style and path configuration to S3

This commit is contained in:
Jesse Wierzbinski 2025-04-15 13:28:12 +02:00
parent 5bb4e967a7
commit 404d63f6d0
No known key found for this signature in database
3 changed files with 13 additions and 1 deletions

View file

@ -449,6 +449,8 @@ export const ConfigSchema = z
public_url: url.describe( public_url: url.describe(
"Public URL that uploaded media will be accessible at", "Public URL that uploaded media will be accessible at",
), ),
path: z.string().optional(),
path_style: z.boolean().default(true),
}) })
.optional(), .optional(),
validation: z.strictObject({ validation: z.strictObject({

View file

@ -159,11 +159,15 @@ export class Media extends BaseInterface<typeof Medias> {
bucket: config.s3.bucket_name, bucket: config.s3.bucket_name,
accessKeyId: config.s3.access_key, accessKeyId: config.s3.access_key,
secretAccessKey: config.s3.secret_access_key, secretAccessKey: config.s3.secret_access_key,
virtualHostedStyle: !config.s3.path_style,
}); });
await client.write(path, file); await client.write(path, file);
const finalPath = config.s3.path
? join(config.s3.path, path)
: path;
return { path }; return { path: finalPath };
} }
} }
} }

View file

@ -153,6 +153,12 @@ convert_vectors = false
# region = "us-east-1" # region = "us-east-1"
# bucket_name = "versia" # bucket_name = "versia"
# public_url = "https://cdn.example.com" # public_url = "https://cdn.example.com"
# Adds a prefix to the uploaded files
# path = "versia"
# Use path-style URLs during upload (e.g. https://s3.example.com/versia)
# instead of the default virtual-hosted style (e.g. https://versia.s3.example.com)
# This is required for some S3-compatible services, such as MinIO
# path_style = true
[validation] [validation]
# Checks user data # Checks user data