I've been trying modules and libraries for the last couple of hours. From socketio-fileupload to other of that sort. None worked for me. I just want something basic and simple if possible. I'm unable to transfer the file to the server. How can I do this with the least hassle possible?
html
<input required type='file' id="imageUpload" accept=".png, .jpg, .jpeg" />
<button class="saveImage">Upload Image</button>
client
function updateAvatar(){
$('.saveImage').on('click',function(){
var file = $('#imageUpload').val();
var filename = file.name;
var filesize = file.size;
var enc = file.encoding;
console.log(file);
socket.emit('update-avatar', {
data : file,
size : filesize,
name : filename,
enc : enc
}
);
});
}
server
socket.on('update-avatar',function(data){
console.log(data);
var filename = path.basename(data.name);
var filepath = path.join('./uploads', filename);
});