3

I need to upload a DICOM image using ASP.Net Core SDK 3.0 preview8 using Blazor Framework.

Is JSInterop needed in this case? How does that helpful in solving the problem?

What are the required steps to follow in this case? A sample code will be useful.....

0

2 Answers 2

2

As @Kornelis mentioned you can use BlazorFileReader to get the byte stream of a file. I'm using the lib. in a similar way to upload files. I just don't upload to the server, instead I'm creating sas token for a blob in Azure Blob Storage and use the storage REST API to upload the file data.

To load the file from an input html element:

<input type="file" @ref="@inputTypeFileElement" @ref:suppressField /> 

Note: currently in prev8 there is a know bug using @ref for this cases. That way the @ref:suppressField is needed.

For getting the file stream with the library:

foreach (var file in await fileReaderService.CreateReference(inputTypeFileElement).EnumerateFilesAsync()) { using (Stream stream = await file.OpenReadAsync()) { await viewModel.UploadAsync(stream); } } 

And here is how I process the stream:

public async Task UploadAsync(Stream stream) { using (HttpContent fileStreamContent = new StreamContent(stream)) { //Add any headers you require here fileStreamContent.Headers.Add("x-ms-blob-type", "BlockBlob"); var response = await _httpClient.PutAsync("your upload endpoint url", fileStreamContent); } } 
Sign up to request clarification or add additional context in comments.

Comments

1

I would imagine you could use blazor file reader: https://github.com/Tewr/BlazorFileReader Upload it to byte array and then do what you want with it.

Comments

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.