Hi Eric,
Thanks for contacting Syncfusion support.
We have analyzed with your query to send the memory stream from client side to the server side controller method at our end. Unfortunately, we can’t post the memory stream directly from the client end to the server controller. However, we can convert the memory stream to a base 64 string and post it from the client to the server controller method and then convert the obtained base 64 string obtained in the server controller method into memory stream to achieve your requirement. As shown in the below code snippet.
[Index.razor]
//Converting a memory stream to base 64 string
string baseString = Convert.ToBase64String(stream.ToArray());
//Send the base 64 text
await Http.SendJsonAsync(HttpMethod.Post, "/api/Sample/Sample", new PostValue { value = baseString }); |
[sampleController] (server side controller)
[HttpPost("[Action]")]
public void Sample([FromBody] PostValue value)
{
//converting the base 64 string back to memory stream
MemoryStream sample = new MemoryStream(Convert.FromBase64String(value.value));
//saving the file locally in the machine from the memory stream
FileStream fs;
using (fs = new FileStream("output.pdf", FileMode.OpenOrCreate))
{
sample.CopyTo(fs);
}
} |
For your convenience, we have attached the sample to achieve your requirement as explained above in the below link. Please check it.
Here, in the sample, we have converted a simple pdf file memory stream (been created dynamically) to a base 64 string at the client end and converted the same base 64 string to a memory stream obtained in the server controller method and saved pdf file in the (Server directory) as output.pdf . Please let us know if you need any further assistance.
Regards,
Prem Kumar M