Load image from GFS
See original GitHub issueHello guys
I use superagent and I do like it. But despite the fact I spend the last days on the documentation, I am facing a problem that I do not succeed to resolve
I make a request to load an image inside react-dropzone Here is my request inside a react component
loadImage(){
request.get('https://localhost:3000/' + 'api' +'/banner'+ this.props.path )
.set({'Authorization': 'Bearer ' + Auth.getToken()})
.then((res, err) => {
if (err) {
console.log(err)
}
console.log(res.status)
if (res) {
// this.state.universities=
console.log(res)
var buf2 = new Buffer( res.text).toString('base64');
console.log(buf2)
var img = new Image();
img.src = "data:image/png;base64," + buf2 ;
img.class='content';
this.state.file=img
}
})}
I do a post when I drop a file and I succeed, but I do not understand how to get the image from my API. I did spend a lot of time taking my hairs out of my head.
Here is my rest API
router.get('/banner/admin/university/:id', (req, res) => {
//TODO improve it
console.log('--------------get the banner --------------')
University.findById(req.params.id, function (err, uni) {
var readstream = gfs.createReadStream({_id: uni.banner});
readstream.on("error", function(err){
console.log(err)
res.send("No image found with that title");
});
readstream.pipe(res);
})
})
Is there something I am missing ?
I get the data inside the res.text, but it is not readable. How can I put it as a file ? If you consider this not as an issue but as a newbie question, where can I get the right help about it ?
Best regards,
Arn
Issue Analytics
- State:
- Created 6 years ago
- Comments:13 (5 by maintainers)
Top Results From Across the Web
Load image from GFS · Issue #1262 · ladjs/superagent - GitHub
I do a post when I drop a file and I succeed, but I do not understand how to get the image from...
Read more >How to display images from mongodb gridfs - Stack Overflow
For display the images correctly with gridfs You have to follow this ... "image/png"){ // Read output to broswer const readstream = gfs....
Read more >GridFS Guide: How to Upload Files and Images to MongoDB ...
Then with the help of the method openDownloadStreamByName() on gfs stream, we can easily render an image as it returns a readable stream....
Read more >Overlaying weather maps and cloud images with GFS data ...
... GFS wind and pressure surface analysis with the corresponding OPC surface analysis map and the GOES West satellite image. We get the ......
Read more >How can I use GridFS to load a file on the server after I create ...
I do have code to load files client side using GridFS but I am ... ObjectID, which GFS doesn't understand. this.collection.update(image.
Read more >Top Related Medium Post
No results found
Top Related StackOverflow Question
No results found
Troubleshoot Live Code
Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start FreeTop Related Reddit Thread
No results found
Top Related Hackernoon Post
No results found
Top Related Tweet
No results found
Top Related Dev.to Post
No results found
Top Related Hashnode Post
No results found
Top GitHub Comments
Okay I solved everything. ( I wanted to do more complicated than necessary … )
here is the explanation Serverside :
Client side
I didnt need to use superagent to request the image. Just an Url. I do not know why I didnt think about this before.
Thank for helping me a lot with the header thing !
Haa thank you.
it is working !! 👍