Я пытаюсь прочитать изображение с клиентской стороны, закодированное в base64. Как читать с nodejs?
Мой код:
// add to buffer base64 image
var encondedImage = new Buffer(image.name, 'base64');
fs.readFile(encondedImage, "base64", function(err, buffer){
if ( err ) {
console.log('In read file')
console.log(err)
} else {
// check err
lwip.open(buffer, 'jpg', function(err, image){
console.log('in open')
if ( err ) console.log(err)
if ( image ) console.log(image)
// check 'err'. use 'image'.
// image.resize(...), etc.
});
}
})
Но я получил эту ошибку:
In read file
[Error: Path must be a string without null bytes.]
* РЕШЕНИЕ *
lwip
принять буфер в открытом методе.
// add to buffer base64 image from step
var encondedImage = new Buffer(image.name, 'base64');
// check err
lwip.open(encondedImage, 'jpg', function(err, image){
// image.resize(..), etc
});