Firefox and FormData Objects — Gotcha/Issue

When sending over a file using FormData objects and XMLHttpRequest via POST, make sure not to name the file object with the string “file” as in

formData.append(“file”, e.target.files[0]);

Use any other name than “file”, e.g.:

formData.append(“userfile”, e.target.files[0]);

Not sure what happens under the hood, but for some reason with a PHP based server (perhaps the problem was with the framework being used), the POST never occurred until I changed the key string naming.

Share