8 AnswersNew Answer
What data do you have? And from/where you wanna store them? Image data use to be store in database as byte arrays then you convert them into string and send to client where it is set as image source
<DD> ty for your response, Don't know what data it is . But i am using fetch to get the image ,now i want to store whatever image data(in bytes or any other format) fetch function send us, in a jpeg file . Fyi , it is not about sending to a client or anyone else . I could download the file through browser but just want to see how it can be done using node js.
Abhay I would say it makes no sense to try download image using nodejs, streams are used to write/read files between client and server, you should simply fetch the image then download it using normal js
Abhay Ohh, I get you now, can you share the code, I can revise it easier than writing the whole thing
<DD> my code is a mess ,anyway i tried writing something by following this link and going through other articles ,but didn't understand how to do it. https://developer.mozilla.org/en-US/docs/Web/API/ReadableStream/pipeTo The above article explains how to use "pipeto" to direct readableStream to writeableStream but i am unable to create writeableStream . Though ,I coded a simple writestream but it didn't work out . let writeStream = fs.createWriteStream("something.jpeg" ); Error : TypeError [ERR_INVALID_ARG_TYPE]: The "transform.writable" property must be an instance of WritableStream. Received an instance of WriteStream.
<DD> not interested in doing that but thks.
The question is VAGUE! But the comment shows that you want to store image data which can be a large array containing pixel values. The easiest method is to explore the fetch response by printing it to the console, I believe there's a handy function returned that makes it easy to retrieve image data The hard method is to send the whole image to the client, and using html5 canvas, you can use the image data to get the data, you can then send this data back to the server...