Merge pull request #16467 from strapi/fix/provider-s3-video-uploads

This commit is contained in:
Marc 2023-04-21 14:43:38 +02:00 committed by GitHub
commit cd4c3298d4
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23

View File

@ -27,7 +27,7 @@ interface File {
// eslint-disable-next-line @typescript-eslint/no-var-requires
require('aws-sdk/lib/maintenance_mode_message').suppress = true;
function assertUrlProtocol(url: string) {
function hasUrlProtocol(url: string) {
// Regex to test protocol like "http://", "https://"
return /^\w*:\/\//.test(url);
}
@ -93,11 +93,13 @@ export = {
}
// set the bucket file url
if (assertUrlProtocol(data.Location)) {
file.url = baseUrl ? `${baseUrl}/${fileKey}` : data.Location;
if (baseUrl) {
// Construct the url with the baseUrl
file.url = `${baseUrl}/${fileKey}`;
} else {
// Default protocol to https protocol
file.url = `https://${data.Location}`;
// Add the protocol if it is missing
// Some providers like DigitalOcean Spaces return the url without the protocol
file.url = hasUrlProtocol(data.Location) ? data.Location : `https://${data.Location}`;
}
resolve();
};