Answer the question
In order to leave comments, you need to log in
How to send mp3 file to server?
Hello everyone
, I have a post request, in the parameter of which I need to upload a file in mp3 format,
I want to upload the file through and through onChange pull the file and send it (I use React)
is this even real? if not, how is it generally better to implement file transfer (what to convert to and how to do it)? <input type="file" />
Answer the question
In order to leave comments, you need to log in
1) You can in the traditional way. In the form, use the input tag with the file type with the restriction set to accept only *.mp3. The form is submitted by a button with type submit.
2) In an advanced way. The form also uses the input tag with the file type, which is restricted to only accept *.mp3. The difference is that you need to send the form fields without fail only through an ajax request. In this case, the field with the file is read using the FileReader object (old browsers do not have it, for example, IE 10-, so the method does not roll for them), a binary request packet is formed in a special way, and this packet in the form of base64 is transmitted by Ajax to the server.
PS: no matter what method of sending you choose, the file can be attached to the form only at the initiative of the user, regardless of whether you use a simple form submission or try to pick up the file from the input FileReader.
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question