i am using mongodb as my database and node.js as a server. i managed to save image array as buffer data. can i send those buffer data to the front-end and display. is it faster than sending image URL s?,
You can store image in your own database and send It to the front-end, but It is not recommended if you don't have a strong enough server to process that buffer datas as described here.
Related
I want to get a video frame from the camera of the user, detect a face using OPENCV.JS - get vectors data from it), create a new WebGL-canvas (using three.js) and place a cube related to the vectors data (for example, the nose).
I read a lot of different solutions but I am still not sure what will performance the best.
Do everything in the client. (using js-workers)
Send frame from client to server, process the answer, send the data back to the client. (node.js + sockets)
I will appreciate any answer.
I can save the file to disk with formidable and then send the file bits to mongo with node, but how can I just handle streaming the file bits directly to mongo?
I don't need gridfs, these are small files. Just want to write them to the normal store.
Use options.fileWriteStreamHandler to setup your own stream. Then write to mongodb if the API accepts a stream
I was creating an application in react for uploading video and using a REST API to send that to the server and store in S3. I also wanted the simple audio version of the video for some other tasks and I am confused as to what might be the better way:
Creating audio file on the fly when it is needed using node-ffmpeg package and not store it anywhere
Start converting the video file to audio on the browser client only, and posting that to the server for storage along with the video.
Just post the video to the server and use queue system for creating a new task for video conversion to audio and then save that to the S3 storage.
The second method seems to be saving some compute power on the server but it might be a problem if the video upload completes, audio conversion is still going on and the client disconnects.
Would appreciate some help, thanks.
I'm testing out postgres binary abilities by storing some mp3 data in a table. I've read you're supposed to store them in an external filesystem like S3, but for various reasons I don't want to do that right now.
So, for now I'd like to test storing files in the db. The mp3 files are TTS mp3 files from a third-party and I've stored them in a postgres table. This is working ok. But how do I serve them to the client? In other words:
client http requests the files.
node requests (pg-promise) the records (one or many).
the data arrives from db to node in binary format.
??? Do I have to convert it to a mp3 file before sending? Can I send the binary file directly? Which would be better?
client receives file(s)
client queues files in order for playing audio.
My main question is whether I need to convert the binary record I received from postgres before sending, and how to do that?
I want to open an image and send it and send to the sockets that are connected in my nodejs server.
The problem is when I'm trying to send some image via socket.write(myImage); because the method write() can't send it as an image object. The "solution" that i've found is to create a buffer from my image, copy in another buffer and parse it to a base64 encode and send this using socket.write(myBase64Img), receive it in my Qt client and decode that image with openCV. the problem is that this is very expensive. There is another way to send my image via TCP sockets?
PS: I can't send the URL of the image, I want to send the image.
Thanks!
You should be able to write the raw image data to the socket without base64-encoding it, just pass a Buffer containing that binary data to write(). You could also stream the data if you don't have the image completely in memory already since that would help save on memory usage.
Assuming that you're dealing with an image that is already on disk, the right way to do this is to stream the image directly from disk to the socket.
var stream = fs.createReadStream(filePath);
stream.pipe(socket);
See the docs for details:
fs.createReadStream
Stream#pipe