Skip to content
This repository has been archived by the owner on Mar 14, 2019. It is now read-only.

Insert from a Stream on the Server

Philipp edited this page Mar 1, 2015 · 2 revisions
// You must have a ReadStream with some data; it can be any stream.
// We're using the standard output from a command as an example.
var readStream = spawn('ls', []).stdout;

// Create the FS.File instance
var newFile = new FS.File();

// Attach the ReadStream data to it. You must tell it what the content type is.
newFile.attachData(readStream, {type: 'text/plain'});

// Optionally provide a file name
newFile.name('ls_result.txt');

// Insert the file, which will save the metadata and
// store the stream data into all defined stores.
// `Files` is an `FS.Collection` instance defined elsewhere.
Files.insert(newFile);