Upload Document to Google Drive

I'd like to have a Documents table (an AppSheet Database), which users can upload a document to in the app. I'd like to then have an automation to upload that document to Google Drive in a specific subfolder. So I've started writing a App Script to handle that automation, but I'm not sure how to get the file contents and upload it correctly into Google Drive. I then want to have the link to the file in the Documents table.

I get an error as the input_file is just a string of where the AppSheet file is stored, not the actual content. I'm passing it the [Upload] column that contains the file.

This is as far as I got:

 

 

 

function uploadFile(filename,file,subfolder,owner) {
  var projects_folder = DriveApp.getFolderById("123abcExample")
  var search = projects_folder.searchFolders("title = '"+subfolder+"'")
  var folder
  if (search.hasNext())
    folder = folders.next();
  else
    folder = projects_folder.createFolder(subfolder)
  console.log(folder.getName());

  file = folder.createFile(file)
  console.log(file.getName())
  file.setName(filename).setOwner(owner)
  console.log(file.getName())
  return file.getId()
}

 

 

 
How should I proceed? I can't find examples of this online, am I missing something?

P.S. Alternatively, is there a more simple way of saving file/image uploads to Google Drive directly?
0 2 115
2 REPLIES 2

Would it be easier to have a Documents table with few columns where one of them is a file column. With the file column, you can specify the folder where that file is saved. Then you could open the file directly from the app. Or is there some other requirements for your documents folder?

It turns out the files are already in Google Drive, I don't know why I didn't know that. I now have an App Script that gets the File ID and makes a URL for me.

Top Labels in this Space