Closed Centerworx closed 10 months ago
@AlemTuzlak See above.
The issue here is that you can't parse files from request.formData(), you have to use Remix unstable_parseMultiPartFormData. You get the streamed data from the frontend there and you can return it to your action however you like, I wrote an article explaining how yo ucan upload your images to supabase and return paths here:
https://alemtuzlak.hashnode.dev/uploading-images-to-supabase-with-remix
Although this set
helper seems really interesting, is there a doc page anywhere on how it works?
No, it's an internal react-hook-form method, but it is exposed form repo and it's basically doing a similar thing to what you're already doing with the added advantage that it automatically appends the data set to the original data object. I found it by deep diving react-hook-form library, and how it handled dot syntax parsing.
getValidatedFormData is not returning the file data.
Issue is here: https://github.com/Centerworx/remix-hook-form/blob/d082e1d0e7929451505db9ac0519952860d56bc4/src/utilities/index.ts#L49
FormData Blob/FIles are not handled. JSON cannot hold a file.
you can use react-hook-form set function to do this.
With this set function you can eliminate all the string parsing and conversion you are doing in "generateFormData" it would just become the below:
The only issue with using react-hook-form set function is it will not use empty [] in keys urlSearchParams or dotKey syntax. You can use my "cleanArrayStringKeys" function to allow for empty [] or remove those test to conform to react-hook-form standards, you could even throw an error if there is an empty [].
If you don't want to simplify your code, you can just add this to "tryParseJSON", this should do the trick, but should be tested:
on a side note:
value instanceof Blob
-> Some node servers (<16, It can be imported in 16+) may not have access to Blob and so it could break some projects. See ref: https://stackoverflow.com/questions/14653349/node-js-cant-create-blobs#:~:text=41-,Since%20Node.js%2016,-%2C%20Blob%20can