使用rn-fetch-blob从gridfs到React-Native应用程序的readStream

时间:2018-08-16 20:59:07

标签: mongodb react-native encoding gridfs-stream

我试图从我的nodejs服务器创建一个readStream到一个react-native应用程序,并不断出现此编码错误:

rn-fetch-blob:

[Error: Failed to convert data to base64 encoded string, this might due to the 
 source data is not able to convert using this encoding.] code: 'EUNSPECIFIED'

带有rn-fetch-blob的fetch-blob:

let data = '';
RNFetchBlob.fs.readStream(
  URL,
  'base64',
  409600,
  100
)
.then((stream) => {
  stream.open();
  stream.onData((chunk) => {
    data += chunk;
    console.log(data);
  });
  stream.onError((err) => {
    console.log('err', err);
  });
  stream.onEnd(() => {
    // FileViewer.open(data);
  });
});

}

nodejs代码:

gfs.files.findOne({ metadata: markId, filename: req.query.fileName }, (err, file) => {
if (file) {
  const readstream = gfs.createReadStream(file.filename, {encoding: 'base64'});
  readstream.pipe(res);
  // console.log(readstream)
  // res.json(file)
} else {
  err => console.log(err)
  res.sendStatus(500);
  console.log(500)
}

})

任何帮助将不胜感激。

谢谢。

0 个答案:

没有答案