13
Views
1
Comments
[PWA Camera & Microphone] How to access server side?
Forge component by Ruben Goncalves
0
Published on 12 Mar 2020
Application Type
Reactive

Great component for PWA and Reactive apps, which I've got working fine.

I'm a little stuck as to how I can use captured audio and video server side. I'd like to either save the audio in the database, or use it to post to an API. How do I convert the object created into something I can then process?

Champion
Rank: #139

Hey Darren,

You can call TakePictureFromCamera passing the ReturnDataURI as true. You can then pass the resulting DataURI to a server action where the picture can be saved.



The DataURI is a string with the following format:

data:image/png;base64,iVBORw0KGgoAAA
ANSUhEUgAAAAUAAAAFCAYAAACNbyblAAAAHElEQVQI12P4
//8/w38GIAXDIBKE0DHxgljNBAAO9TXL0Y4OHwAAAABJRU
5ErkJggg==

The Base64 is the part after the comma ","

So, in the server action:

1) Split the DataURI by the delimiter ","

2) Convert the second element of the string split (Base64) to BinaryData

3) Do what you want with the BinaryData, e.g. save it on the database



Cheers,

David