Store Input File Selected In Redux To Upload Later
Solution 1:
You can store the file in the same way your store other text fields. The value attribute of a input of type file contains the path of the file saved as string. This value can be saved in the Redux store as a string field.
When you finally process the form inputs you can use this value to load and send the file to the server. As per MDN
Sending files with HTML forms is a special case. Files are binary data — or considered as such — whereas all other data is text data. Because HTTP is a text protocol, there are special requirements for handling binary data.
The
enctypeattribute This attribute lets you specify the value of theContent-TypeHTTP header included in the request generated when the form is submitted. This header is very important because it tells the server what kind of data is being sent. By default, its value isapplication/x-www-form-urlencoded. In human terms, this means: "This is form data that has been encoded into URL parameters."If you want to send files, you need to take three extra steps:
- Set the
methodattribute toPOSTbecause file content can't be put inside URL parameters.Set the value of
enctypetomultipart/form-databecause the data will be split into multiple parts, one for each file plus one for the text data included in the form body (if text is also entered into the form).Include one or more
File pickerwidgets to allow your users to select the file(s) that will be uploaded.
Post a Comment for "Store Input File Selected In Redux To Upload Later"