0

I have a XMLHttpRequest:

chat.sendMessage = function (message) {
    var xhr = new XMLHttpRequest();
    xhr.open("POST", options["url"], true);
    console.log(message["image"]);
    xhr.send(JSON.stringify(message));
};

As you see I log image field directly before sending message. And the log writes File object in a console. But on the server side this field is empty. Why?

This is a function where I attach image to image field:

imageAddWindowSubmit.onclick = function () {
    ...
    message.addImage(chatInputImage.files[0] || "");
    if (message["text"] || message["image"]) {
       chat.sendMessage(message);
    }
}; 

AddImage method:

this.addImage = function (image) {
    this.image = image;
};
Alexander Shpindler
  • 811
  • 1
  • 11
  • 31

1 Answers1

0

You have to add enctype="multipart/form-data" on your form for uploading file.

If you can use jQuery then check this link otherwise you have to add some code to handle file, check this link

Community
  • 1
  • 1
EikiProg
  • 83
  • 9