From 243b71bfa75cdaff18e1135f885ca9e7098974cc Mon Sep 17 00:00:00 2001 From: Kevin Ruder Date: Thu, 31 Oct 2019 10:29:39 +0100 Subject: [PATCH] An image URL is created for each uploaded image, these can be used as sources in image tags. The FileListEntryModel is expanded to include URL --- BlazorInputFile/FileListEntryImpl.cs | 1 + BlazorInputFile/IFileListEntry.cs | 2 ++ BlazorInputFile/wwwroot/inputfile.js | 5 ++++- 3 files changed, 7 insertions(+), 1 deletion(-) diff --git a/BlazorInputFile/FileListEntryImpl.cs b/BlazorInputFile/FileListEntryImpl.cs index 4ec8883..49d669e 100644 --- a/BlazorInputFile/FileListEntryImpl.cs +++ b/BlazorInputFile/FileListEntryImpl.cs @@ -22,6 +22,7 @@ public class FileListEntryImpl : IFileListEntry public long Size { get; set; } public string Type { get; set; } + public string Url { get; set; } public Stream Data { diff --git a/BlazorInputFile/IFileListEntry.cs b/BlazorInputFile/IFileListEntry.cs index 9a6f5fc..c59038b 100644 --- a/BlazorInputFile/IFileListEntry.cs +++ b/BlazorInputFile/IFileListEntry.cs @@ -13,6 +13,8 @@ public interface IFileListEntry string Type { get; } + string Url { get; } + Stream Data { get; } event EventHandler OnDataRead; diff --git a/BlazorInputFile/wwwroot/inputfile.js b/BlazorInputFile/wwwroot/inputfile.js index 13e7ab3..25432cd 100644 --- a/BlazorInputFile/wwwroot/inputfile.js +++ b/BlazorInputFile/wwwroot/inputfile.js @@ -6,13 +6,16 @@ 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: ++nextFileId, lastModified: new Date(file.lastModified).toISOString(), name: file.name, size: file.size, - type: file.type + type: file.type, + url: window.URL.createObjectURL(file) }; elem._blazorFilesById[result.id] = result;