Skip to content

Commit

Permalink
Implemented access to the relative path property for uploading folders (
Browse files Browse the repository at this point in the history
#131)

* Implemented access to the relative path property for uploading folders

Added the ability to access webkitRelativePath from the IFileInfo interface, allowing for the support of structured folders to be uploaded using <input>.

* Changed the webkitRelativePath property to a Dictionary of nonstandard File properties

* Remove unused class
  • Loading branch information
DouglasDwyer authored Jun 12, 2020
1 parent 1a1b8ee commit bd326ae
Show file tree
Hide file tree
Showing 5 changed files with 30 additions and 3 deletions.
7 changes: 7 additions & 0 deletions src/Blazor.FileReader/FileReaderRef.cs
Original file line number Diff line number Diff line change
Expand Up @@ -115,6 +115,11 @@ public interface IFileInfo
/// </summary>
string Name { get; }

/// <summary>
/// Returns a list of non-standard DOM properties attached to the object, like the webkitRelativePath property.
/// </summary>
Dictionary<string,object> NonStandardProperties { get; }

/// <summary>
/// Returns the size of the file in bytes.
/// </summary>
Expand Down Expand Up @@ -238,6 +243,8 @@ public FileInfo()

public string Name { get; set; }

public Dictionary<string,object> NonStandardProperties { get; set; }

public long Size { get; set; }

public string Type { get; set; }
Expand Down
12 changes: 10 additions & 2 deletions src/Blazor.FileReader/script/FileReaderComponent.ts
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,7 @@ interface IReadFileParams {

interface IFileInfo {
name: string;
nonStandardProperties: any;
size: number;
type: string;
lastModified: number;
Expand Down Expand Up @@ -143,13 +144,20 @@ class FileReaderComponent {
}

public GetFileInfoFromFile(file: File): IFileInfo {
const result = {
var result = {
lastModified: file.lastModified,
name: file.name,
nonStandardProperties: null,
size: file.size,
type: file.type
};

var properties: any = new Object();
for (let property in file) {
if (Object.getPrototypeOf(file).hasOwnProperty(property) && !(property in result)) {
properties[property] = file[property];
}
}
result.nonStandardProperties = properties;
return result;
}

Expand Down
8 changes: 8 additions & 0 deletions src/Blazor.FileReader/wwwroot/FileReaderComponent.js

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion src/Blazor.FileReader/wwwroot/FileReaderComponent.js.map

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

4 changes: 4 additions & 0 deletions src/Demo/Blazor.FileReader.Demo.Common/IndexCommon.razor
Original file line number Diff line number Diff line change
Expand Up @@ -57,6 +57,10 @@ There are other demos in the menu.
Output += $"{nameof(IFileInfo)}.{nameof(fileInfo.Size)}: {fileInfo.Size}{nl}";
Output += $"{nameof(IFileInfo)}.{nameof(fileInfo.Type)}: {fileInfo.Type}{nl}";
Output += $"{nameof(IFileInfo)}.{nameof(fileInfo.LastModifiedDate)}: {fileInfo.LastModifiedDate?.ToString() ?? "(N/A)"}{nl}";
foreach(string property in fileInfo.NonStandardProperties.Keys)
{
Output += $"{nameof(IFileInfo)}.{property} (nonstandard): {fileInfo.NonStandardProperties[property]}{nl}";
}
Output += $"Reading file...";
this.StateHasChanged();
Console.WriteLine(Output);
Expand Down

0 comments on commit bd326ae

Please sign in to comment.