diff --git a/lib/stores/DataStore.js b/lib/stores/DataStore.js index b87fbaa7..4f95e895 100644 --- a/lib/stores/DataStore.js +++ b/lib/stores/DataStore.js @@ -106,6 +106,27 @@ class DataStore extends EventEmitter { return resolve({ size: 0, upload_length: 1 }); }); } + + /** + * Parses the Base64 encoded metadata received from the client. + * + * @param {String} metadata_string tus' standard upload metadata + * @return {Object} metadata as key-value pair + */ + _parseMetadataString(metadata_string) { + const kv_pair_list = metadata_string.split(','); + + return kv_pair_list.reduce((metadata, kv_pair) => { + const [key, base64_value] = kv_pair.split(' '); + + metadata[key] = { + encoded: base64_value, + decoded: Buffer.from(base64_value, 'base64').toString('ascii'), + }; + + return metadata; + }, {}); + } } module.exports = DataStore; diff --git a/lib/stores/GCSDataStore.js b/lib/stores/GCSDataStore.js index 7265d429..6008221b 100644 --- a/lib/stores/GCSDataStore.js +++ b/lib/stores/GCSDataStore.js @@ -92,7 +92,9 @@ class GCSDataStore extends DataStore { const file = new File(file_id, upload_length, upload_defer_length, upload_metadata); const gcs_file = this.bucket.file(file.id); + const parsedMetadata = this._parseMetadataString(upload_metadata); const options = { + contentType: parsedMetadata.type.decoded, metadata: { metadata: { upload_length: file.upload_length, @@ -131,9 +133,11 @@ class GCSDataStore extends DataStore { return new Promise((resolve, reject) => { const file = this.bucket.file(file_id); + const parsedMetadata = this._parseMetadataString(data.upload_metadata); const options = { offset, metadata: { + contentType: parsedMetadata.type.decoded, metadata: { upload_length: data.upload_length, tus_version: TUS_RESUMABLE, diff --git a/lib/stores/S3Store.js b/lib/stores/S3Store.js index e2c268c2..9dfc1668 100644 --- a/lib/stores/S3Store.js +++ b/lib/stores/S3Store.js @@ -233,27 +233,6 @@ class S3Store extends DataStore { }); } - /** - * Parses the Base64 encoded metadata received from the client. - * - * @param {String} metadata_string tus' standard upload metadata - * @return {Object} metadata as key-value pair - */ - _parseMetadataString(metadata_string) { - const kv_pair_list = metadata_string.split(','); - - return kv_pair_list.reduce((metadata, kv_pair) => { - const [key, base64_value] = kv_pair.split(' '); - - metadata[key] = { - encoded: base64_value, - decoded: Buffer.from(base64_value, 'base64').toString('ascii'), - }; - - return metadata; - }, {}); - } - /** * Uploads a part/chunk to S3 from a temporary part file. *