tus-node-server
tus-node-server copied to clipboard
server hook get metadata
server.on(EVENTS.EVENT_UPLOAD_COMPLETE, (event) => { console.log(event.file.upload_length); console.log(event.file.upload_metadata ); });
How to get event.file.upload_length and event.file.upload_metadata ? I can't get those value from event hook complete. Possible to get my req.get(..) from event ?
Hi @bhstahl , let me know if you need more info on this.
Thanks @cometta, that should suffice. I'm a bit tied up at the moment with a few other projects, but i'll try to take a look soon. If you have any ideas, feel free to fork, fix and submit a PR with the patch!
I wanted to share a though regarding the db tracking. FileStore uses configstore underneath which saves everything inside a json file. It would be nice to be able to pass an adapter to the FileStore which and store the data to different storage engines (e.g. Redis or a NoSQL database) instead of a plain text file, for performance reasons if the server is used in large scale.
@cometta , maybe this will help out a bit (it's ES6 by the way):
import _ from 'lodash';
// http://tus.io/protocols/resumable-upload.html#upload-metadata
const metadataStringToObject = (stringValue) => {
const keyValuePairList = stringValue.split(',');
return _.reduce(keyValuePairList , (metadata, keyValuePair) => {
let [key, base64Value] = keyValuePair.split(' ');
metadata[key] = new Buffer(base64Value, "base64").toString("ascii");
return metadata;
}, {});
};
server.on(EVENTS.EVENT_UPLOAD_COMPLETE, (event) => {
console.log(metadataStringToObject(event.file.upload_metadata));
});
Hello @alolis try this console.log(event.file.upload_metadata ) // output: undefined
@cometta , are you using the metadata object key on your tus client?
If you do not send anything from the client then upload_metadata will be empty.
@alolis
on the client
let upload = new tus.Upload(file, {
metadata: { testmeta: 'something' }
//commented out other options..
});
in the serverside
app.all('/upload/*'), function(req, res) {
console.log("check metadata",req.get('metadata')); //undefined
});
server.on(EVENTS.EVENT_UPLOAD_COMPLETE, (event) => {
console.log(event.file.upload_length);
console.log(event.file.upload_metadata ); //undefined
});
Have you try out yourself? which version of tus.client are you using
@cometta, not sure what the problem might be. Seems to be working on my side with tus-js-client version 1.2.1 and tus-node-server version 0.2.1.
Maybe try to print the whole req on the console and see what's in there for starters. On server side I use the following:
app.all('/uploads/*', (req, res) => {
server.handle(req, res);
});
Same as in the examples.
I'm seeing this too. If I change to a FileStore on the back end, the metadata comes across. If I use GCS datastore, I can't see anything. Metadata is only sent (or visible) on the File Creation event.
Closed in #344