Skip to content

Commit 3ac64e5

Browse files
authored
Merge pull request transloadit#844 from vith/tus-metadata-filetype
Tus plugin: rename metadata field: type→filetype
2 parents 33e494f + 3207893 commit 3ac64e5

File tree

1 file changed

+15
-1
lines changed

1 file changed

+15
-1
lines changed

src/plugins/Tus.js

Lines changed: 15 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -166,7 +166,21 @@ module.exports = class Tus extends Plugin {
166166
this.resetUploaderReferences(file.id)
167167
resolve(upload)
168168
}
169-
optsTus.metadata = file.meta
169+
170+
const copyProp = (obj, srcProp, destProp) => {
171+
if (
172+
Object.prototype.hasOwnProperty.call(obj, srcProp) &&
173+
!Object.prototype.hasOwnProperty.call(obj, destProp)
174+
) {
175+
obj[destProp] = obj[srcProp]
176+
}
177+
}
178+
179+
// tusd uses metadata fields 'filetype' and 'filename'
180+
const meta = Object.assign({}, file.meta)
181+
copyProp(meta, 'type', 'filetype')
182+
copyProp(meta, 'name', 'filename')
183+
optsTus.metadata = meta
170184

171185
const upload = new tus.Upload(file.data, optsTus)
172186
this.uploaders[file.id] = upload

0 commit comments

Comments
 (0)