I've a list which contains upload files:
let files = [File, File, File...];
and another upload file to compare:
let file = ...;
I want to check the file
exists in the list or not (by comparing name/width/height/size/type
);
Here is my way:
let f = files.find(function (x) {
return x.name === file.name && x.type === file.type &&
x.width === file.width && x.height === file.height &&
x.size === file.size;
});
if (f) {
// exist
}
But x.width
, x.height
, file.width
and file.height
always return undefined
.
undefined
always equals to undefined
(of course =))), but it's not my mean, I want to get the real value instead.
Thanks to this answer, I've edited some where but not finished yet.
let f = files.find(function (x) {
let x_img = new Image();
x_img.onload = function () {
let file_img = new Image();
file_img.onload = function () {
// we can compare x_img width/height and file_img width/height here
// but these functions look like the callback function
// so we can't delay to get width and height
};
file_img.src = window.URL.createObjectURL(file);
};
x_img.src = window.URL.createObjectURL(x);
// the main predicate here
return x.name === file.name && x.size === file.size && x.type === file.size &&...
// and how to compare width and height?
});
Can you help me to complete the code? Thank you!