Created
May 25, 2016 23:27
-
-
Save lwakefield/483197c02e2cb994521b8ca3d719ea47 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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(); | |
} | |
}); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
I also have this error. I observed that if the file exceeds at 60kb this error will be thrown