0

I'm trying to upload a video to the Dailymotion API with ajax.

In my script i have :

                //upload the video and get the url
                var xhr =  new XMLHttpRequest();
                xhr.open('POST', upload_url, true);
                var formData = new FormData(document.getElementById("myForm"));
                xhr.send(formData);

My script is working but i have a problem, how can I specify which file field i want to use ?

If you see var formData = new FormData(document.getElementById("myForm"));, myForm is the entire form, if my file input has id="myInput", how can i specify that ?

I don't want to send all my form, but just one specific field.

Thanks !

1
  • 1
    Is it an <input type="file" ,if yes then you can use document.getElementById('myInput').files[0]; Commented Jun 16, 2015 at 16:50

2 Answers 2

1

This do what i want :

var file = document.getElementById("myInput").files[0];
var formData = new FormData();
formData.append('file', file);
Sign up to request clarification or add additional context in comments.

Comments

0

Create en empty FormData and add the file value to it manually:

var file = document.getElementById("myInput").value;
var formData = new FormData();
formData.append('file', file);

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.