tus-node-server icon indicating copy to clipboard operation
tus-node-server copied to clipboard

server hook get metadata

Open cometta opened this issue 9 years ago • 9 comments

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 ?

cometta avatar Aug 18 '16 23:08 cometta

Hi @bhstahl , let me know if you need more info on this.

cometta avatar Aug 30 '16 08:08 cometta

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!

bhstahl avatar Aug 30 '16 14:08 bhstahl

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.

alolis avatar Aug 31 '16 14:08 alolis

@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));
});

alolis avatar Sep 01 '16 10:09 alolis

Hello @alolis try this console.log(event.file.upload_metadata ) // output: undefined

cometta avatar Sep 01 '16 12:09 cometta

@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 avatar Sep 01 '16 12:09 alolis

@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 avatar Sep 01 '16 13:09 cometta

@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.

alolis avatar Sep 01 '16 14:09 alolis

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.

edwar64896 avatar Nov 25 '16 01:11 edwar64896

Closed in #344

Murderlon avatar Dec 13 '22 13:12 Murderlon