-
Notifications
You must be signed in to change notification settings - Fork 15
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feature: change upload component's return object
- Loading branch information
Yakali, Yagizhan Necat (ADV D EU TR AP&I PIA1)
committed
May 16, 2023
1 parent
39b693e
commit 52275ca
Showing
3 changed files
with
63 additions
and
6 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,18 @@ | ||
namespace SiemensIXBlazor.Objects | ||
{ | ||
public class IXFile | ||
{ | ||
public string Name { get; } | ||
public long Size { get; } | ||
public string Type { get; } | ||
public string Base64Data { get; } | ||
|
||
public IXFile(string name, long size, string type, string base64Data) | ||
{ | ||
Name = name; | ||
Size = size; | ||
Type = type; | ||
Base64Data = base64Data; | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,8 +1,21 @@ | ||
export function fileUploadEventHandler(caller, elementId, eventName, funtionName) { | ||
const element = document.getElementById(elementId); | ||
element.addEventListener(eventName, (e) => { | ||
e.detail[0].arrayBuffer().then(data => { | ||
caller.invokeMethodAsync(funtionName, new Uint8Array(data)); | ||
}) | ||
const files = e.detail; | ||
|
||
const fileDataArray = []; | ||
for (let i = 0; i < files.length; i++) { | ||
const file = files[i]; | ||
const reader = new FileReader(); | ||
reader.onloadend = function () { | ||
const base64Data = reader.result.split(',')[1]; | ||
fileDataArray.push({ name: file.name, size: file.size, type: file.type, data: base64Data }); | ||
|
||
if (fileDataArray.length === files.length) { | ||
caller.invokeMethodAsync(funtionName, fileDataArray); | ||
} | ||
}; | ||
reader.readAsDataURL(file); | ||
} | ||
}) | ||
} |