im making an app that works like this: when the button is pressed , the app starts sound recording and automatically stops after 10seconds. i have ventured into many discussions and it just made me more confused about stuff.
i know the blocks ive made might be hella wrong and stupid regarding the saving process, so my questions are- how do i save an mp3(the recording) file in google drive?
and where does the file thats recorded actually saved in the mobile device?
updates: i figured out the app script and stuff for google drive and now the mp3 file does get saved in google drive. unfortunately somehow the mp3 file that gets uploaded is unplayable, like a corrupted file of sorts and i dont know what to do
yeah youre right, i figured it out the hard way. unfortunately so, even when i save my file as 3gp file, drive somehow hardcodes it back to mp3 and gets saved as mp3.
heres the app scripts im using
function doPost(e) {
try {
// 1. Validate incoming data
if (!e || !e.postData || !e.postData.contents) {
return ContentService.createTextOutput("Error: No data received");
}
// 2. Create file with timestamp (as .3gp)
const timestamp = new Date().toISOString()
.replace(/[:.]/g, "-");
const audioBlob = Utilities.newBlob(
e.postData.contents,
"audio/3gpp", // Correct MIME type for .3gp
`alert_${timestamp}.3gp` // Force .3gp extension
);
// 3. Save to SafetyPendant folder
const parentFolder = DriveApp.getFoldersByName("SafetyPendant").hasNext() ?
DriveApp.getFoldersByName("SafetyPendant").next() :
DriveApp.createFolder("SafetyPendant");
const file = parentFolder.createFile(audioBlob);
// 4. Return success with file URL
return ContentService.createTextOutput(JSON.stringify({
status: "success",
url: file.getUrl(),
format: "3gp" // Clarify format for app
}));
} catch(error) {
return ContentService.createTextOutput(JSON.stringify({
status: "error",
message: error.message
}));
}
}