Hello,
So what i'm trying to achieve right now is uploading a file to an REST API with some custom headers. To achieve this instead of using the standard SaveUrl and RemoveUrl i just use the ValueChanged event to catch whenever a new file is added and upload that manually through my own http client with the custom headers.
However i don't seem to get this to work. Here is the code i have:
As seen in the code i basically use the same idea as documented for the regular InputFile component: https://docs.microsoft.com/en-us/aspnet/core/blazor/file-uploads?view=aspnetcore-6.0&pivots=server#upload-files-to-a-server
For the InputFile component it does work, however now when i build the same MultipartFormDataContent using the Stream provided by the SfUploader it does send to the backend but the data i retrieve from the file stream in the backend is always empty.
Any ideas what i am doing wrong here and how i can fix this?
I have attached the example project with this code. To test just run both the API and BlazorApp at the same time and try the upload.
Thanks,
Bram
|
private async Task OnChange(UploadChangeEventArgs args)
{
UploadFiles file = args.Files.SingleOrDefault();
//Due to FileInfo ambiguity reference between syncfusion and system.io added inline namespace for system.IO.
System.IO.FileInfo info = new System.IO.FileInfo(file.FileInfo.Name);
var stream = new MemoryStream(file.Stream.ToArray());
using (StreamReader sr = new StreamReader(stream))
{
var HtmlString = sr.ReadToEnd();
var rteValue = HtmlString;
}
} |
That worked thanks!