Flask Request.files Returns ImmutableMultiDict([])
Solution 1:
Would you mind elaborating on the issue a bit more? It's expected that Flask Request returns an ImmutableMultiDict:
MultiDict object containing all uploaded files. Each key in files is the name from the
<input type="file" name="">. Each value in files is a Werkzeug FileStorage object.It basically behaves like a standard file object you know from Python, with the difference that it also has a
save()function that can store the file on the filesystem.Note that files will only contain data if the request method was
POST,PUTorPATCHand the<form>that posted to the request hadenctype="multipart/form-data". It will be empty otherwise.See the MultiDict / FileStorage documentation for more details about the used data structure.
Solution 2:
I believe the problem is with your serialisation of the form. - Try giving this a read.
You can also use something similar to the below:
(function($) {
  $.fn.serializeFiles = function() {
    var form = $(this),
        formData = new FormData(),
        formParams = form.serializeArray();
    $.each(form.find('input[type="file"]'), function(i, tag) {
      $.each($(tag)[0].files, function(i, file) {
        formData.append(tag.name, file);
      });
    });
    $.each(formParams, function(i, val) {
      formData.append(val.name, val.value);
    });
    return formData;
  };
})(jQuery);
You can eliminate which part is not working by not preventing the form to submit, and see if by default; the form submits files' to the backend. - It's highly unlikely that you're passing the correct data from the way you're serialising the form.
Post a Comment for "Flask Request.files Returns ImmutableMultiDict([])"