Converting audio file when uploaded to google cloud storage

自闭症网瘾萝莉.ら 提交于 2020-04-15 06:42:14

问题


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.


回答1:


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.



来源:https://stackoverflow.com/questions/56358921/converting-audio-file-when-uploaded-to-google-cloud-storage

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!