I'm creating a Contact Manager for customers in ElectronJS. I have a form that saves all the data of the customers in the computer as a JSON (using app.getPath()). But now I want to save an image of each customer, in a folder in the same path.
The problem I'm facing right now, is that with the input type="file", you get the fakepath and the only way I know how to copy an image and store to the other folder is knowing the path of the image.
<input type="file" class="form-control" value="Upload Image" accept="image/png, image/jpeg" id="image" onchange="previewFile()">
I've been surfing @ stackoverflow and the closest solution I've found was using:
var inStr = fs.createReadStream(file.name);
var outStr = fs.createWriteStream(pathOfImageSaved);
This works nice, but only works if the image is inside the project's folder. If the image is on desktop or another folder, then it does not work.
So my problem is, from an image ""uploaded"" into an <input type="file">
how to use it to save it to another folder. I was thinking of creating an instance of the image (new Image()
) but It did not work either.
I've tried all this links (and more) but didn't find the solution:
Fastest way to copy a file in Node.js
Silent saving image in electron.js
Image File Upload and Retrieve in Electron
How do I save image locally in electron app
how to copy an image and save it in a new folder in electron