So in my backend (express and mongodb) I have a field inside of post model called picture and it’s type is string. So in the frontend (React) I want the user to be able to select a file and then the file will be converted to a string then sent to the backend. I do not know how to do this nor have I been able to find any tutorial or blog on this. Thanks in advance!
2
Answers
Google "convert file to string js". Then you need to do a POST request by putting that string to the BODY in your POST request but of course you need to handle this operation in your backend in one of your endpoints.
The functionality you are looking for is called FileReader API.
You might take a look at a very similar question here: How to convert file to base64 in JavaScript?.