Extra data in Skipper stream

450 Views Asked by At

Currently writing code to make a skipper gridfs adapter. When you call upload, files are passed in the callback and I would like to add an extra field to the files that contain the metadata of a gridfs store and the ID of a gridfs store.

I'm looking through the Upstream code in skipper and see something called stream.extra. I'm guessing it's for passing extra data, how would I go about using this?

1

There are 1 best solutions below

0
On BEST ANSWER

Thanks for working on this! You can add extra metadata to your stream by putting it on the __newFile object in the receiver's _write method. For example, in the bundled s3Receiver, you can see this on line 61:

__newFile.extra.fsName = fsName;

which is adding the newly generated filename as metadata on the uploaded file object. In your controller's upload callback, you can retrieve the extra data from the returned file objects:

req.file('myFile').upload(function (err, files) {
    var newFileName = files[0].extra.fsName;
});