-
Notifications
You must be signed in to change notification settings - Fork 0
/
multipleFileSelect.js
114 lines (84 loc) · 2.48 KB
/
multipleFileSelect.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
/**
* Classe Image
* @param {File} file le fichier image
* */
function VdmImage(pfile){
this.file = pfile;
this.fileName = "";
this.fileType = "";
this.fileBase64 = "";
if(arguments.length == 0){
throw new Error("Parametre manquant au constructeur de "+this.constructor.name);
}
if(this.file || !this.file instanceof File ){
throw new TypeError("Un objet de type File est requis au constructeur de "+this.constructor.name);
}
this.getFileName = function(){
return file.name;
};
this.fileName = this.file.name;
this.fileType = this.file.type;
//this.fileBase64 = this.file.
}
VdmImage.prototype = {
prototype : VdmImage,
getFileName : function(){
return this.fileName;
},
};
var TestObj={
/**
* Retourne un tableau d'objet VdmImage
* @param {Array.<File>} array des fichier selectionne dans le file Input
* @returns {Array.<VdmImage>}
* */
getImageFiles : function getImageFiles(files){
var imageFiles = [];
if(files && files[0]){
for(var idx = 0; idx < files.length; idx++){
readImage( files[idx], idx );
}
}
}
};
function readImage(file, idx) {
var ul = document.getElementById('fileList');
var li = document.createElement('li');
var div = document.createElement('div');
var img = document.createElement('img');
var str;
var fileReader;
var imgObj;
var canvas;
var context;
fileReader = new FileReader();
fileReader.onloadend= function(){
str = 'File ' + (idx+1) + ' : ' + file.name ;
div.innerHTML = str;
img.src = fileReader.result;
li.appendChild(div);
li.appendChild(img);
canvas = document.createElement('canvas');
canvas.width=1024;
canvas.height = 768;
context = canvas.getContext('2d');
context.drawImage(img.src, 0, 0, canvas.width, canvas.height);
div = document.createElement('div');
div.innerHTML = ' resize image content base64 : ';
img.src = canvas.toDataURL(file.type);
li.appendChild(div);
li.appendChild(img);
ul.appendChild(li);
};
fileReader.readAsDataURL(file);
}
$(document).ready(function(){
$("#asd").change(function(){
var imageFiles = this.files;
if(files && files[0]){
for(var idx = 0; idx < files.length; idx++){
readImage( files[idx], idx );
}
}
});
});