<@U024BRJ7RHQ> grab the audio and send it to your ...
# orm-help
v
@Kent C. Dodds grab the audio and send it to your server, let the server to save it to postgresql in binary .. don't base64 it, if 100-200 recordings are concurrent streams as it is going to be very pricey, performance-wise. If recording 1 per browser, and saved on server, it should be fine. 3 minute is rather short, so keep it in browser, and once done, send it over to the server. (ref: https://developers.google.com/web/fundamentals/media/recording-audio , https://www.postgresql.org/docs/7.3/jdbc-binary-data.html#:~:text=PostgreSQL%20provides%20two%20distinct%20ways,type%20OID%20in%20your%20table)
k
So when I record the audio, what I have is a
Blob
. How do I send that to the backend? I need to serialize that to a string right?
What I'm doing right now is using FileReader to read that blog as a DataURL and then posting that to my backend.
Also, thanks for the postgres reference, but I'm not sure how that translates to prisma. I see that if I set my schema to
Bytes
that property requires a Buffer, but a buffer of what?
v
Got carried away with life ... back now
Copy code
//   const recorder = document.getElementById('recorder');
k
Thanks, I actually figured it out
and I tried a real-life test and found that submitting the form data with the blob was actually worse than the base64 encoding from a data size standpoint
v
That line will give your the recorder as per google ref above, then
Copy code
recorder.addEventListener('change', function(e) {
    const file = e.target.files[0];  // capture the stream here
    const url = URL.createObjectURL(file); // grab a URL that is assignable 
    // Do something with the audio file.
    // (e.g. Upload it to a server by attaching it to an XMLHttpRequest)
  });
3 minutes audio is considered small .. and if one browser one time one stream goes, it should be performant to encode base64 and send it over as text
If that is the case, you have it covered ...
k
Yeah, that's my case 👍 Thanks for taking the time to help!
v
Great .. awesome it worked out for you. thx
Just remember you can connect to postgresql via .raw() feature of prisma ... for the features (bindings) that are not baked in yet. fYI