Hi,
Is it possible to change the display style in FileUpload component? One drawback is the height.
|
|
Hi
Thank you so much for the guidance which was exactly what I needed. There is another case. I have the following model classes.
public Class clsFile{ public string FileName { get; set; } public byte[] Content { get; set; }}
public class clsUser{ name , family , public List<clsFile> UserFiles {get;set;}}
I read the site guide. In the following event
private void OnFileUploader (UploadChangeEventArgs args){......}
How can I fill clsFile? Given that its type is byte [].
Thank you
|
|
Hi Ponmani Murugaiyan,
Thank you for your answer. Unfortunately, this method did not work either. If we define dto as follows. Is it possible in the ValueChange event to put the contents of the files selected by the user as IFromFile in dto?
I want to send dto to WebApi at HttpClient.Post()
public Class clsFile{ public string FileName { get; set; } public IFromFile Content { get; set; }}
public class clsUser{ name , family , public List<clsFile> UserFiles {get;set;}}
Thank you
|
private void OnChange(UploadChangeEventArgs args)
{
foreach (var file in args.Files)
{
var path = @"path" + file.FileInfo.Name;
FileStream filestream = new FileStream(path, FileMode.Create, FileAccess.Write);
file.Stream.WriteTo(filestream);
filestream.Close();
file.Stream.Close();
byte[] bytes = file.Stream.ToArray();
string base64 = Convert.ToBase64String(bytes);
}
} |
|
|
Hi Ponmani Murugaiyan,
Thank you very much for your help. The bug has been fixed. I have a service layer whose output is List<dto>. I receive List<dto> files that the user has uploaded in the past from the service layer as dto. But unfortunately it is not displayed in the uploader component.
<SfUploader @ref="objUploader" AllowMultiple=true Files="@lstFiles" >
<UploaderEvents ValueChange="..." OnRemove="....." FileSelected="...."> </UploaderEvents>
</SfUploader>
protected async override Task OnInitializedAsync()
{
//Fill lstFiles
{
Hi Ponmani Murugaiyan,
Actually, I do not have a code for these problems yet. But the scenario is as follows:
In the insert.razor page, several photos can be uploaded for the employee. As follows:
In the edit.razor page, I want to show the files that have been uploaded in the past to the user. The user can delete old files or add new ones. In other words, when loading the edit.razor page, I want to display the above image to the user.
Thank you
|
<SfUploader @ref="UploaderObj">
<UploaderFiles>
<UploaderUploadedFiles Name="Nature" Size=500000 Type=".png"></UploaderUploadedFiles>
<UploaderUploadedFiles Name="TypeScript Succinctly" Size=12000 Type=".pdf"></UploaderUploadedFiles>
<UploaderUploadedFiles Name="ASP.NET Webhooks" Size="500000" Type=".docx"></UploaderUploadedFiles>
</UploaderFiles>
...
</SfUploader>
|
Hi Ponmani Murugaiyan,
Excellent was exactly what I wanted. I have the SfUploader component on the edit page and it displays a list of files I have uploaded in the past. Is the user able to download the file from this list(Download files uploaded in the past) In SfUploader Component?
Thank you
|
<SfUploader ID="UploadFiles">
<UploaderFiles>
<UploaderUploadedFiles Name="Nature" Size=500000 Type=".png">UploaderUploadedFiles>
<UploaderUploadedFiles Name="TypeScript Succinctly" Size=12000 Type=".pdf">UploaderUploadedFiles>
<UploaderUploadedFiles Name="ASP.NET Webhooks" Size="500000" Type=".docx">UploaderUploadedFiles>
UploaderFiles>
<UploaderTemplates>
<Template>
<span class='name file-name'>@(context.Name)span>
<span class='file-size'>@(context.Size) bytesspan>
<span class="upload-status">@(context.Status)span>
<span class="fa fa-download" title="Download" @onclick="@(e => OnClick(e, context.Name))">span>
Template>
UploaderTemplates>
<UploaderEvents ValueChange="OnChange" OnRemove="onRemove">UploaderEvents>
SfUploader>
|
|
window.onUpload = (id, filename) => {
let url = https://localhost:44394/api/SampleData/Download?filename= + filename;
window.location.rel='nofollow' href = url;
}; |
|
public FileResult Download(string filename)
{
var filePath = Path.Combine(Directory.GetCurrentDirectory());
IFileProvider provider = new PhysicalFileProvider(filePath);
IFileInfo fileInfo = provider.GetFileInfo("path"+filename);
var readStream = fileInfo.CreateReadStream();
var mimeType = "application/pdf";
return File(readStream, mimeType, filename);
} |
|
|
Hi Ponmani Murugaiyan,
Thank you, the problems have been resolved. Does the default style disappear when using UploaderTemplates?
The colors changed and the row height increased.
I set the styles manually for the items. In upload-status, different styles must be set for success or failure.
Thank you.
|
<SfUploader ID="UploadFiles">
<UploaderTemplates>
<Template>
<span class='name file-name'>@(context.Name)</span>
<span class='file-size'>@(context.Size) bytes</span>
@if (context.Status == "File uploaded successfully")
{
<span class="upload-status-success">@(context.Status)</span>
}
else
{
<span class="upload-status-error">@(context.Status)</span>
}
<span class="fa fa-download" title="Download" @onclick="@(e => OnClick(e, context.Name))"></span>
</Template>
</UploaderTemplates>
<UploaderEvents ValueChange="OnChange" OnRemove="onRemove"></UploaderEvents>
</SfUploader>
<style>
.upload-status-success {
color: green;
}
.upload-status-error {
color: red;
}
</style> |
Hi Ponmani Murugaiyan,
I checked and the problem was fixed. I do not have the option to delete the uploaded file. It is possible to tell me how to do it.
<span class="fa fa-trash " title="remove" @onclick="@(e => OnFileUploaderRemoveClick(e, e.Context.Name,Context.Size))"></span>
Thank you
|
<SfUploader @ref="FileUploader" ID="UploadFiles">
<UploaderTemplates>
<Template>
<span class='name file-name'>@(context.Name)</span>
<span class='file-size'>@(context.Size) bytes</span>
@if (context.Status == "File uploaded successfully")
{
<span class="upload-status-success">@(context.Status)</span>
}
else
{
<span class="upload-status-error">@(context.Status)</span>
}
<span class="fa fa-download" title="Download" @onclick="@(e => OnClick(e, context.Name))"></span>
<span class="e-icons e-file-delete-btn m-2 position-relative"
tabindex="0"
title="Delete @(context.Name)" @onclick="@(() => DeleteFile(context))" />
</Template>
</UploaderTemplates>
<UploaderEvents ValueChange="OnChange"></UploaderEvents>
</SfUploader>
@code {
public SfUploader FileUploader;
[Inject]
protected IJSRuntime JsRuntime { get; set; }
public List<Syncfusion.Blazor.Inputs.FileInfo> files = new List<Syncfusion.Blazor.Inputs.FileInfo>();
private async void DeleteFile(Syncfusion.Blazor.Inputs.FileInfo file)
{
// Delete file from File Upload component
var filename = file.Name;
int idx = files.FindIndex(c => c.Name == filename);
FileInfo[] text = new FileInfo[] { files[idx] };
await FileUploader.Remove(text);
}
private void OnChange(UploadChangeEventArgs args)
{
files = new List<Syncfusion.Blazor.Inputs.FileInfo>();
foreach (var file in args.Files)
{
files.Add(new Syncfusion.Blazor.Inputs.FileInfo()
{
Name = file.FileInfo.Name,
Id = file.FileInfo.Id,
RawFile = file.FileInfo.RawFile,
Size = file.FileInfo.Size,
Status = file.FileInfo.Status,
StatusCode = file.FileInfo.StatusCode,
FileSource = file.FileInfo.FileSource,
Input = file.FileInfo.Input,
List = file.FileInfo.List,
Type = file.FileInfo.Type,
ValidationMessages = file.FileInfo.ValidationMessages
});
}
} |
Hi Ponmani Murugaiyan ,
Thank you so much
Hi Ponmani Murugaiyan ,
I encountered a problem. On the edit page, we show the user a list of files they have uploaded in the past. Suppose a user deletes a number of old files and adds and saves new files. In the web api I get a list of files that I do not know which of these files have been uploaded in the past (for this file I do not need to make changes to the database) and which one the user has deleted (I have to delete from the database) and which one the user Newly uploaded (save as a new file in the database). It should be noted that the user can upload different files with the same name or the same size.
Thank you
Hi Sarah,
We are validating the requirement. We will update the further details in two business days(24rd June 2022).
Regards,
Udhaya Kumar D
Hi Sarah,
We can upload the same file in the uploader with the same name and size as mentioned in the below screenshot (By using the sample provided in the previous update). We request you to provide the exact requirement details that you want to achieve. This will help us validate the requirement further and provide you with a better solution.
Screenshot:
|
|
Regards,
Udhaya Kumar D.
Hi UdhayaKumar Duraisamy,
Suppose we have three files with the same name and size (file A, File B, file C.) On the create page, the user uploads file A, B. In the edit page, we display file A, B in the SfUploadercomponent to the user. Suppose the user deletes file B and adds file C and click the save button. In this case, there are two files in the list of files sent to the web api that I can not find out whether these two files are the same A, B or delete file B from the bank and insert the C file in the bank.
thank you
Hi Sarah,
We have validated your requirement in our end. i.e., After uploading the file with same name and size in uploader component, the file information gets stored in list. so if you delete the specific file from the uploaded list, the file(s) with exact primary/unique data(name,id,etc) will get removed from it. It’s indented behavior of the file upload component.
Regards,
Mohanraj M
Hello,
Thank you for your reply.
I did not understand. If possible, introduce a source code so that I can check.
thank you
Hi Sarah,
While we update the multiple duplicate files, the uploader will send only one file to the server. We have shared the Syncfusion File Upload sample below for your reference. Also, we request you to provide additional details about the query as mentioned below, This will help us validate the query further and provide you with a better solution.
1. Exact Requirement details with Video illustration.
2. Issue reproducing sample (or modify the attached sample).
3. Issue replication steps.
Sample: https://www.syncfusion.com/downloads/support/directtrac/general/ze/FileUploadSample1880542140
Regards,
Udhaya Kumar D