What's the best way to batch upload audio files to a specific Google Drive folder?

Hey folks, I’m stuck on a project where I need to upload multiple .amr audio files to a particular folder in Google Drive. Right now, I’m using the startIntentSender method to show a picker for choosing a folder, which works fine for one file. But I want to send several files at once without the picker, straight to a folder I specify in the code. I’ve looked everywhere and I’m totally lost. The Google Drive API is no longer supported, so I’m not sure what to do. Is there a good method for uploading multiple files? Here’s a snippet of what I’ve got so far:

CloudStorage.CloudApi.newCloudContent(mCloudConnection)
    .setResultCallback(new ResultCallback<CloudApi.CloudContentResult>() {
        @Override
        public void onResult(CloudApi.CloudContentResult result) {
            if (!result.getStatus().isSuccess()) {
                Log.i(TAG, "Failed to create new content.");
                return;
            }
            OutputStream outputStream = result.getCloudContent().getOutputStream();

            try {
                FileInputStream fileInputStream = new FileInputStream(mAudioFiles.get(i).getPath());
                byte[] buffer = new byte[1024];
                int bytesRead;
                while ((bytesRead = fileInputStream.read(buffer)) != -1) {
                    outputStream.write(buffer, 0, bytesRead);
                }
            } catch (IOException e1) {
                Log.i(TAG, "Oops! Can't write file contents.");
            }

            // More code here for metadata and file creation
        }
    });

Any ideas on how to make this work for multiple files without the picker? Thanks!

Having worked extensively with Google Drive APIs, I can confidently say that the REST API is your best bet for batch uploading. It’s still fully supported and quite robust for handling multiple files.

To implement this, you’ll need to:

  1. Set up OAuth 2.0 authentication
  2. Retrieve the target folder ID
  3. Use the files.create endpoint in a loop

The key is to prepare a MultipartContent for each file, including both the file metadata and the actual file content. This allows you to specify the parent folder ID in the metadata, ensuring all files land in the right place.

While it requires some initial setup, this method is far more efficient and flexible than using the picker for each file. It also opens up possibilities for more advanced Drive operations in your app.

hey mate, have u tried using the Google Drive REST API? it’s still supported and lets u upload multiple files to a specific folder. u’d need to authenticate, get the folder ID, and then use the files.create endpoint for each file. might be easier than the current approach. good luck!

I’ve been in a similar situation before, and I found that using the Google Drive REST API is indeed the way to go. It’s a bit of a learning curve, but once you get the hang of it, it’s pretty straightforward.

First, you’ll need to set up OAuth 2.0 for authentication. Then, use the Drive API to get the folder ID where you want to upload. After that, you can use a loop to iterate through your audio files and upload them one by one using the files.create endpoint.

Here’s a rough outline of the process:

  1. Set up credentials
  2. Get folder ID
  3. Loop through files
  4. For each file, create a File metadata object
  5. Use files.create with the folder ID as the parent

It’s more code upfront, but it’ll save you headaches in the long run. Plus, you can reuse this setup for other Google Drive operations in the future.