-1

I have array of video files. i tried to upload. in below code console gives result empty object. How to select video file and upload. is it possible??

var pictureInput=['hp.mp4'];
var myFormData = new FormData();
myFormData.append('pictureFile', pictureInput[0]);    
console.log(myFormData)
$.ajax({
   url: 'uploadurl',
   type: 'POST',
   processData: false, 
   contentType: false, 
   dataType : 'json',
   data: myFormData
});
Arunkumar
  • 5,150
  • 4
  • 28
  • 40

2 Answers2

0

For security reasons, it is not possible to read or upload files by name from a script. The user must either explicitly select the files from a dialog, or drag-and-drop them to the page. (If it were allowed, pages would be able to read and transmit any file on your system simply by knowing the name, which is not a good thing!)

You can find out more about how to let users specify files on the web here: https://developer.mozilla.org/en/docs/Using_files_from_web_applications

Mark
  • 559
  • 3
  • 11
0

Use file object instead of file name only.

Previously i made successful this with Google App Engine (Java) and Angular 1.5

Look this accepted answer too. jQuery equivalent to XMLHttpRequest's upload?

var formData = new FormData();
formData.append('pictureFile',FILE_OBJECTS[0]);

$.ajax({
  url: "YOUR_URL",
  type: "POST",
  data: formData,
  cache: false,
  contentType: false,
  processData: false,
  xhr: function() { // Custom XMLHttpRequest
    var myXhr = $.ajaxSettings.xhr();
    return myXhr;
  },
}).success(function(data) {
  console.log("Success")
}).error(function(data) {
  console.log("Error")
});
Community
  • 1
  • 1
Arun Shinde
  • 1,185
  • 6
  • 12
  • How to use FILE_OBJECTS into the Array – Arunkumar Apr 12 '16 at 14:32
  • I want to know. how to push the File object into the Array instead of string – Arunkumar Apr 12 '16 at 14:33
  • Their are multiple ways. Since you are implemented in Angular JS so I implemented using Angular directive only. This is the best approach from my point of view. See this Plunkr. Printed file objects on browser console. https://plnkr.co/edit/hYwg2pBaAMBlZeN3R34j?p=preview – Arun Shinde Apr 12 '16 at 14:52