I create a form input file to let the user browse their file and upload to the server After that I use Jquery to get the data of the file and try to use AJAX to send the data of the file to the Node router to process. However the data file after sending becoming an { object File } and I don't know how to process the data.
Below is my HTML and AJAX code to send file data
HTML:
<input type="file" accept="image/png, image/jpeg, image/gif" id="feature-image" />
AJAX:
$("#feature-image").on("change", function () { var featureImageFile = $('#feature-image').get()[0].files[0]; $.ajax({ type: 'GET', data: {file: featureImageFile } , url: '/test', contentType: false, processData: false, success: function() { console.log("OK"); } }); });
SERVER:
router.get("/test", (req, res) => { var file = req.query; console.log(file); });
When I print out the file, it returns me an object: {object File} and I don't know how to deal with this. I want to get the data to store the the file using fs library to the server. Please help me !