How to use FormData in Rescript?

Hi All,
I was trying to build a custom file input that selects files using the HTML input element and upload the files using FormData in Rescript.
I was checking this below mentioned documentation as reference-
Please look at the code under the attached link of rescript playground to look onto the code I have written-

This code gives me no entries for FormData while consoling the formData variable.

I am unable to implement this. Can anyone help me with proper example.

Thanks in advance!!:slightly_smiling_face:

Without trying out your code, you even can’t console.log Formdata in javascript.
You can use the keys, values and entries functions to iterate over the data.

Hi, what you’re describing is actually standard HTML behaviour, so I’m not sure what is the custom part here. E.g. this is a standard HTML form (without React):

<form method="post" action="/send-file">
  <label for="send-file">Send a file:</label>
  <input name="file" id="send-file" type="file">
  <input type="submit" value="Submit">
  <input type="reset" value="Cancel">

It will allow you to:

  • Choose a file
  • Submit the form and send a POST /send-file request on submit
  • Cancel i.e. clear out the file selection

Internally, it uses FormData to temporarily hold the state of the form in memory before submitting it. But that detail is only needed if you want to manipulate the form data somehow before allowing it to submit, or validate it somehow.

If you can explain specifically what extra functionality you are trying to implement, maybe we can point you in the right direction.