Home > front end >  how to upload audio file to google drive with url with google apps script
how to upload audio file to google drive with url with google apps script

Time:01-13

Can someone point out where I'm going wrong. I'm trying to upload a audio file to my Google drive with Google apps script. The file uploads but I can't play it.

Here is my function:

function upload() {
    
  var url = 'https://api.twilio.com/2010-04-01/Accounts/ACxxxxxxxxxxxxxx/Recordings/RExxxxxxxxxxxxxxx';
  
    var blob = UrlFetchApp.fetch(url).getBlob().getBytes();

  var folder = DriveApp.getFolderById('xxxxxxxxxxxxxxx');  
  blob = Utilities.newBlob(blob, 'audio/x-wav', 'testFile.wav');
  var file = folder.createFile(blob); 
}

CodePudding user response:

The problem here is not with the snippet of code you are using - since the file is indeed uploaded properly, but with the browser and third party cookies.

In order for the audio to be played, third party cookies should be enabled for your browser since Google Drive is not able to play the files by itself.

Another option is to simply choose one of the third party apps suggested by Google in order to play the audio file.

enter image description here

  •  Tags:  
  • Related