Redux-form: dealing with File objects in fields

Created on 16 Mar 2016  路  3Comments  路  Source: redux-form/redux-form

I have a problem with handling files:

  1. I add a file to fields, e.g. to an "attachments" array
  2. Stuff is validated at some point -> everything is fine
  3. I submit the form -> everything is fine
  4. However, if submission fails, and I try to re-submit, the File objects in the attachments array have been reduced to Objects after the first submission. At this points the objects have also lost their properties lastModified, size, type etc.

My field config is following:

"attachments[].id",
"attachments[].url",
"attachments[].file", <- the original File

I imagine that the problem has probably something to do with deep-cloning the fields at some-point (due to immutability) where the File object is converted to a plain object.

Any opinions whether I should continue building a hack where I store only ids of the files in the fields and the File references mapped to ids somewhere else, or is someone perhaps working with the problem already?

Most helpful comment

Published as v5.2.3.

All 3 comments

Heh, I stumbled into this when working with building a file upload that allowed multiple files. From what I understood the problem begins on https://github.com/erikras/redux-form/blob/master/src/reducer.js#L29

Files are special and I think you have to add a verification if typeof === 'File' or something. I'm looking into it. My hack so far is to create a unique id for each file (new Date().valueOf() + Math.Random(10000,99999)) save the files in components state and then recovering from state on handleSubmit

Published as v5.2.3.

This thread has been automatically locked since there has not been any recent activity after it was closed. Please open a new issue for related bugs.

Was this page helpful?
0 / 5 - 0 ratings

Related issues

chienvuhoang picture chienvuhoang  路  3Comments

m2mathew picture m2mathew  路  3Comments

2easy picture 2easy  路  3Comments

srajchevski picture srajchevski  路  3Comments

yy-hh picture yy-hh  路  3Comments