Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[FIX] S3 uploads not working for custom URLs #7443

Merged
merged 2 commits into from
Jul 14, 2017
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
11 changes: 9 additions & 2 deletions packages/rocketchat-file-upload/server/config/AmazonS3.js
Original file line number Diff line number Diff line change
Expand Up @@ -32,8 +32,10 @@ const configure = _.debounce(function() {
const AWSSecretAccessKey = RocketChat.settings.get('FileUpload_S3_AWSSecretAccessKey');
const URLExpiryTimeSpan = RocketChat.settings.get('FileUpload_S3_URLExpiryTimeSpan');
const Region = RocketChat.settings.get('FileUpload_S3_Region');
const SignatureVersion = RocketChat.settings.get('FileUpload_S3_SignatureVersion');
const ForcePathStyle = RocketChat.settings.get('FileUpload_S3_ForcePathStyle');
// const CDN = RocketChat.settings.get('FileUpload_S3_CDN');
// const BucketURL = RocketChat.settings.get('FileUpload_S3_BucketURL');
const BucketURL = RocketChat.settings.get('FileUpload_S3_BucketURL');

if (!Bucket || !AWSAccessKeyId || !AWSSecretAccessKey) {
return;
Expand All @@ -43,7 +45,8 @@ const configure = _.debounce(function() {
connection: {
accessKeyId: AWSAccessKeyId,
secretAccessKey: AWSSecretAccessKey,
signatureVersion: 'v4',
signatureVersion: SignatureVersion,
s3ForcePathStyle: ForcePathStyle,
params: {
Bucket,
ACL: Acl
Expand All @@ -53,6 +56,10 @@ const configure = _.debounce(function() {
URLExpiryTimeSpan
};

if (BucketURL) {
config.connection.endpoint = BucketURL;
}

AmazonS3Uploads.store = FileUpload.configureUploadsStore('AmazonS3', AmazonS3Uploads.name, config);
AmazonS3Avatars.store = FileUpload.configureUploadsStore('AmazonS3', AmazonS3Avatars.name, config);
}, 500);
Expand Down
14 changes: 14 additions & 0 deletions packages/rocketchat-file-upload/server/startup/settings.js
Original file line number Diff line number Diff line change
Expand Up @@ -90,6 +90,20 @@ RocketChat.settings.addGroup('FileUpload', function() {
},
i18nDescription: 'Override_URL_to_which_files_are_uploaded_This_url_also_used_for_downloads_unless_a_CDN_is_given.'
});
this.add('FileUpload_S3_SignatureVersion', 'v4', {
type: 'string',
enableQuery: {
_id: 'FileUpload_Storage_Type',
value: 'AmazonS3'
}
});
this.add('FileUpload_S3_ForcePathStyle', false, {
type: 'boolean',
enableQuery: {
_id: 'FileUpload_Storage_Type',
value: 'AmazonS3'
}
});
this.add('FileUpload_S3_URLExpiryTimeSpan', 120, {
type: 'int',
enableQuery: {
Expand Down
12 changes: 7 additions & 5 deletions packages/rocketchat-i18n/i18n/en.i18n.json
Original file line number Diff line number Diff line change
Expand Up @@ -593,10 +593,12 @@
"FileUpload_MediaTypeWhiteListDescription": "Comma-separated list of media types. Leave it blank for accepting all media types.",
"FileUpload_ProtectFiles": "Protect uploaded files",
"FileUpload_ProtectFilesDescription": "Only authenticated users will have access",
"FileUpload_S3_Acl": "Amazon S3 acl",
"FileUpload_S3_AWSAccessKeyId": "Amazon S3 AWSAccessKeyId",
"FileUpload_S3_AWSSecretAccessKey": "Amazon S3 AWSSecretAccessKey",
"FileUpload_S3_Bucket": "Amazon S3 bucket name",
"FileUpload_S3_Acl": "Acl",
"FileUpload_S3_AWSAccessKeyId": "Access Key",
"FileUpload_S3_AWSSecretAccessKey": "Secret Key",
"FileUpload_S3_Bucket": "Bucket name",
"FileUpload_S3_SignatureVersion": "Signature Version",
"FileUpload_S3_ForcePathStyle": "Force Path Style",
"FileUpload_S3_BucketURL": "Bucket URL",
"FileUpload_S3_CDN": "CDN domain for downloads",
"FileUpload_S3_Region": "Region",
Expand Down Expand Up @@ -1877,4 +1879,4 @@
"your_message_optional": "your message (optional)",
"Your_password_is_wrong": "Your password is wrong!",
"Your_push_was_sent_to_s_devices": "Your push was sent to %s devices"
}
}