Solution by OP.
Thanks to seanpj, it turns out I overestimated the complexity of this, now I use this method to upload images and videos:
/** * Create a new file and save it to Drive. */ private void saveFiletoDrive(final File file, final String mime) { // Start by creating a new contents, and setting a callback. Drive.DriveApi.newDriveContents(mDriveClient).setResultCallback( new ResultCallback<DriveContentsResult>() { @Override public void onResult(DriveContentsResult result) { // If the operation was not successful, we cannot do // anything // and must // fail. if (!result.getStatus().isSuccess()) { Log.i(TAG, "Failed to create new contents."); return; } Log.i(TAG, "Connection successful, creating new contents..."); // Otherwise, we can write our data to the new contents. // Get an output stream for the contents. OutputStream outputStream = result.getDriveContents() .getOutputStream(); FileInputStream fis; try { fis = new FileInputStream(file.getPath()); ByteArrayOutputStream baos = new ByteArrayOutputStream(); byte[] buf = new byte[1024]; int n; while (-1 != (n = fis.read(buf))) baos.write(buf, 0, n); byte[] photoBytes = baos.toByteArray(); outputStream.write(photoBytes); outputStream.close(); outputStream = null; fis.close(); fis = null; } catch (FileNotFoundException e) { Log.w(TAG, "FileNotFoundException: " + e.getMessage()); } catch (IOException e1) { Log.w(TAG, "Unable to write file contents." + e1.getMessage()); } String title = file.getName(); MetadataChangeSet metadataChangeSet = new MetadataChangeSet.Builder() .setMimeType(mime).setTitle(title).build(); if (mime.equals(MIME_PHOTO)) { if (VERBOSE) Log.i(TAG, "Creating new photo on Drive (" + title + ")"); Drive.DriveApi.getFolder(mDriveClient, mPicFolderDriveId).createFile(mDriveClient, metadataChangeSet, result.getDriveContents()); } else if (mime.equals(MIME_VIDEO)) { Log.i(TAG, "Creating new video on Drive (" + title + ")"); Drive.DriveApi.getFolder(mDriveClient, mVidFolderDriveId).createFile(mDriveClient, metadataChangeSet, result.getDriveContents()); } if (file.delete()) { if (VERBOSE) Log.d(TAG, "Deleted " + file.getName() + " from sdcard"); } else { Log.w(TAG, "Failed to delete " + file.getName() + " from sdcard"); } } }); }
source share