0

In my Angular 1.x app I have a multiple image upload field. When images are added to the field I want to push some additional data on to the FileList object. I have tried this:

for (var i = 0; i < files.length; i++) {
     files[i].append("File", "default_image", true);
}

The format of my 'files' is as follows:

FileList {0: File, 1: File, 2: File, length: 3}
0: File {name: "001.JPG", lastModified: 1521848990762, lastModifiedDate: Fri Mar 23 2018 23:49:50 GMT+0000 (Greenwich Mean Time), webkitRelativePath: "", size: 136430, …}
1: File {name: "002.JPG", lastModified: 1521848990788, lastModifiedDate: Fri Mar 23 2018 23:49:50 GMT+0000 (Greenwich Mean Time), webkitRelativePath: "", size: 136276, …}
2: File {name: "003.JPG", lastModified: 1521848990815, lastModifiedDate: Fri Mar 23 2018 23:49:50 GMT+0000 (Greenwich Mean Time), webkitRelativePath: "", size: 137365, …}
length: 3

There error I get is:

Uncaught TypeError: Cannot read property 'append' of undefined

georgeawg
  • 48,608
  • 13
  • 72
  • 95
Alan A
  • 2,557
  • 6
  • 32
  • 54
  • To add a property to an object use an assignment operation with a property accessor, i.e. `files[i].File = "default_image";`. – georgeawg Aug 06 '19 at 23:14
  • Possible duplicate of [How can I add a key/value pair to a JavaScript object?](https://stackoverflow.com/questions/1168807/how-can-i-add-a-key-value-pair-to-a-javascript-object/1168814#1168814) – georgeawg Aug 06 '19 at 23:53
  • That worked although I had to use: files[i].defaultImage = true; – Alan A Aug 07 '19 at 07:06

0 Answers0