Skip to content
This repository was archived by the owner on May 5, 2021. It is now read-only.
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
59 changes: 31 additions & 28 deletions BlazorInputFile/wwwroot/inputfile.js
Original file line number Diff line number Diff line change
Expand Up @@ -4,37 +4,40 @@
elem._blazorInputFileNextFileId = 0;

elem.addEventListener('change', function handleInputFileChange(event) {
// Reduce to purely serializable data, plus build an index by ID
elem._blazorFilesById = {};
var fileList = Array.prototype.map.call(elem.files, function (file) {
var result = {
id: ++elem._blazorInputFileNextFileId,
lastModified: new Date(file.lastModified).toISOString(),
name: file.name,
size: file.size,
type: file.type,
relativePath: file.webkitRelativePath
};
elem._blazorFilesById[result.id] = result;

// Attach the blob data itself as a non-enumerable property so it doesn't appear in the JSON
Object.defineProperty(result, 'blob', { value: file });

return result;
});

componentInstance.invokeMethodAsync('NotifyChange', fileList).then(function () {
//reset file value ,otherwise, the same filename will not be trigger change event again
elem.value = '';
}, function (err) {
//reset file value ,otherwise, the same filename will not be trigger change event again
elem.value = '';
throw new Error(err);
});
// Only process if files selected.
if (elem.files.length > 0) {
// Reduce to purely serializable data, plus build an index by ID
elem._blazorFilesById = {};
var fileList = Array.prototype.map.call(elem.files, function (file) {
var result = {
id: ++elem._blazorInputFileNextFileId,
lastModified: new Date(file.lastModifiedDate).toISOString(),
name: file.name,
size: file.size,
type: file.type,
relativePath: file.webkitRelativePath
};
elem._blazorFilesById[result.id] = result;

// Attach the blob data itself as a non-enumerable property so it doesn't appear in the JSON
Object.defineProperty(result, 'blob', { value: file });

return result;
});

componentInstance.invokeMethodAsync('NotifyChange', fileList).then(function () {
//reset file value ,otherwise, the same filename will not be trigger change event again
elem.value = '';
}, function (err) {
//reset file value ,otherwise, the same filename will not be trigger change event again
elem.value = '';
throw new Error(err);
});
}
});
},

toImageFile(elem, fileId, format, maxWidth, maxHeight) {
toImageFile: function toImageFile(elem, fileId, format, maxWidth, maxHeight) {
var originalFile = getFileById(elem, fileId);

return new Promise(function (resolve) {
Expand Down