-
-
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(); | |
} | |
}); |
I also hit the same error
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)
Hello i also got this problem please could you help me ?
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. (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)
`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
Dear @lwakefield This is the simplest solution I've ever seen. So elegant!
But I am having a little problem.
When I upload while in the front I get everything is done and percent 100%
However in the server I get
buffer.js:289 W20170221-12:18:04.740(4)? (STDERR) length += list[i].length; W20170221-12:18:04.741(4)? (STDERR) ^ W20170221-12:18:04.741(4)? (STDERR) W20170221-12:18:04.742(4)? (STDERR) TypeError: Cannot read property 'length' of null W20170221-12:18:04.742(4)? (STDERR) at Function.Buffer.concat (buffer.js:289:24) W20170221-12:18:04.743(4)? (STDERR) at IncomingMessage.<anonymous> (server/main.js:35:32) W20170221-12:18:04.743(4)? (STDERR) at emitNone (events.js:67:13) W20170221-12:18:04.744(4)? (STDERR) at IncomingMessage.emit (events.js:166:7) W20170221-12:18:04.745(4)? (STDERR) at endReadableNT (_stream_readable.js:923:12) W20170221-12:18:04.746(4)? (STDERR) at nextTickCallbackWith2Args (node.js:458:9) W20170221-12:18:04.747(4)? (STDERR) at process._tickCallback (node.js:372:17)
Do you know what may be the case?