Skip to content

Instantly share code, notes, and snippets.

@lwakefield
Created May 25, 2016 23:27
Show Gist options
  • Save lwakefield/483197c02e2cb994521b8ca3d719ea47 to your computer and use it in GitHub Desktop.
Save lwakefield/483197c02e2cb994521b8ca3d719ea47 to your computer and use it in GitHub Desktop.
import { Meteor } from 'meteor/meteor';
WebApp.connectHandlers.use('/file', (req, res) => {
res.setHeader("Access-Control-Allow-Methods", "PUT");
res.setHeader("Access-Control-Allow-Origin", "*");
res.setHeader("Access-Control-Allow-Headers", "Content-Type");
if (req.method === 'OPTIONS') {
res.writeHead(200);
res.end();
return;
} else if (req.method === 'PUT') {
if (!req.headers['content-type'].startsWith('image')) {
res.writeHead(400);
res.end();
}
let getFile = Meteor.wrapAsync(done => {
let chunks = [];
req.on('readable', () => {
chunks.push(req.read());
});
req.on('end', () => {
done(undefined, Buffer.concat(chunks));
});
});
let buffer = getFile();
res.writeHead(200);
res.end();
}
});
@dens14345
Copy link

dens14345 commented Feb 8, 2018

`W20170303-13:05:30.830(8)? (STDERR) buffer.js:289
W20170303-13:05:30.834(8)? (STDERR)       length += list[i].length;
W20170303-13:05:30.834(8)? (STDERR)                       
W20170303-13:05:30.835(8)? (STDERR) 
W20170303-13:05:30.835(8)? (STDERR) TypeError: Cannot read property 'length' of null
W20170303-13:05:30.835(8)? (STDERR)     at Function.Buffer.concat (buffer.js:289:24)
W20170303-13:05:30.845(8)? (STDERR)     at IncomingMessage.<anonymous> (server/gcs.js:65:29)
W20170303-13:05:30.846(8)? (STDERR)     at emitNone (events.js:67:13)
W20170303-13:05:30.846(8)? (STDERR)     at IncomingMessage.emit (events.js:166:7)
W20170303-13:05:30.847(8)? (STDERR)     at endReadableNT (_stream_readable.js:923:12)
W20170303-13:05:30.847(8)? (STDERR)     at nextTickCallbackWith2Args (node.js:458:9)
W20170303-13:05:30.847(8)? (STDERR)     at process._tickCallback (node.js:372:17)`

I also have this error. I observed that if the file exceeds at 60kb this error will be thrown

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment