3

I have an app, where users record audio and then "send" to each other. I'm writing "send", because actually the file is stored on server, and just provided to the recipient, when they want to listen.

My issue is, that I need to reformat the recording (currently .caf) to .mp3, so they will be both smaller and so I can play them with the audioplayer I'm using.

My question then is: Is it possible to have a cloud function trigger on user upload, that would take the .caf file, convert it and in its place put a .mp3 file? Can't find anywhere in the docs where it says whether the new file would have same or different url.

Jakob
  • 4,784
  • 8
  • 53
  • 79

1 Answers1

4

Yes, this would be possible if it exists a Node.js library that does the conversion from .caf to .mp3. You should preferably work with a library that handle asynchronous tasks through promises.

Since you are going to write a different file (different extension) the download URL will be different. But it should not be a problem to manage this situation: you can generate a new download URL for the mp3 file and, for example, save it in the database (or generate this URL on the fly, as shown here in the doc).

You will find in the collection of official Cloud Functions samples some Cloud Functions that manipulate files (and in particular use the tmp directory for that). For example there is the generate-thumbnail and the moderate-images.

However, you have to take into account that the maximum execution time for a Cloud Function is 9 minutes. So if some of your audio files need more than 9 minutes of transformation processing it will be a problem.

Renaud Tarnec
  • 79,263
  • 10
  • 95
  • 121