Extract file content from sfUploader

Hello!

I have a third party document system in a Blazor API.  

I am trying to send the file from the sfUploader to the api. The api does not have SyncFusion and can not. The api uses MinimalAPI and FastEndpoints.  I have the uploader in an sfDialog.  I don't want anything to send on the ValueChanged event.  I only want activity when the user clicks the OK button on the dialog.   Also, I am trying to avoid saving the file to disk as there is no need.  I am using the ValueChanged event to save the file in the args to a form level UploadFiles variable so I can use it on the OnValidModel event.  I don't see any other way to get the file.  The GetFilesDataAsync and GetFileDetails methods don't seem to contain the actual file.  Also, no matter which file object I uses - the UploadFile or Fileinfo, the RawFile property is always empty.  Assume for this example I'm sending a pdf.

The steps I think are needed are:

Convert file to byte array

Send to api

Stream byte array back into a pdf.  (Save file as a test only)

Put the pdf into the document system type variable.


How do I get the pdf (or any type) of file) from the uploader and put it in a byte array?

Thank you









2 Replies

MW Matt Wells March 13, 2024 05:31 PM UTC

I figured it out. Here _uploadFile is an UploadFile type. Now you can send the byte array to toe api. byte[] fileBytes = null!; using (var stream = _uploadFile.File.OpenReadStream(_uploadFile.File.Size)) { using (var reader = new MemoryStream()) { await stream.CopyToAsync(reader); fileBytes = reader.ToArray(); reader.Close(); } stream.Close(); }



KP Kokila Poovendran Syncfusion Team March 15, 2024 09:36 AM UTC

Hi Matt Wells,


Thank you for updating us on your progress. We're glad to hear that you've found a solution to your issue. If you have any further questions or concerns in the future, please don't hesitate to reach out to us for assistance. We're here to help.


Regards,

Kokila Poovendran.


Loader.
Up arrow icon