I trying to upload a picture (and more text data) using AJAX and it works... but only with png. Uummm... I only tried png and jpg, and jpg doesn´t work. I am not using a form. This is my javascript code:
if(window.FileReader)
{
reader = new FileReader();
reader.onloadend = function(e)
{
data["image"] = e.target.result.replace('data:image/png;base64,', '');
$.post('/notifications/simple_message', data, function(result){
console.log(result);
});
};
reader.readAsDataURL(img);
}
And on the server side (using node) I have this:
if(req.body.image)
{
var date = new Date();
var buf = new Buffer(req.body.image, 'base64');
image = req.session.user.name+'-'+date.getTime()+'.png';
fs.writeFile('./public/images/users/'+image, buf);
}
I am using the png extension for the new file... but I tried using jpg and it didn´t work.
Any idea??
Thank you!!
Aucun commentaire:
Enregistrer un commentaire