I recently added Google Drive to Dropbox transfers to WetoDrive, a small app that copies files between cloud accounts on the server. The Dropbox side was routine. The Google side was shaped almost entirely by one choice: the app only asks for the drive.file scope.

This post covers what that scope lets you do, the folder behaviour that surprised me, and the Dropbox upload-session details that matter when the bytes are streaming in from somewhere else.

Why drive.file

To read a user's Drive files you would normally ask for drive.readonly or drive. Both are restricted scopes. If your server stores or handles that data, Google requires a security assessment before you can go live, and it has to be renewed every year. For a small app that is a large fixed cost.

drive.file is not restricted. It gives access to files your app created, plus files the user explicitly opens with your app. The standard way to do the second part is the Google Picker:

const view = new google.picker.DocsView(google.picker.ViewId.DOCS) .setIncludeFolders(true) .setSelectFolderEnabled(true); new google.picker.PickerBuilder() .setDeveloperKey(apiKey) .setAppId(projectNumber) .addView(view) .enableFeature(google.picker.Feature.MULTISELECT_ENABLED) .setOAuthToken(token) .setCallback(onPicked) .build() .setVisible(true); 

Whatever the user ticks in the Picker becomes readable by your app. Nothing else does.

The surprise: a picked folder looks empty

I expected that picking a folder would grant its contents. It doesn't. Under drive.file, a picked folder can be listed, but it only shows the children the user also picked. Pick just the folder and your files.list with '<id>' in parents comes back empty.

So the UX has to say it plainly: tick the folder, then open it and select the files inside (Ctrl or Cmd + A works in the Picker). Subfolders need the same step.

On the server, that means the selection can contain a folder and some of the same files picked loose. Two small rules keep that tidy:

// Folders first. Under drive.file a picked folder only shows the children the // user ticked too, so walking it rebuilds exactly that tree, and a file picked // on its own is then already accounted for rather than landing loose. usort($metas, fn ($a, $b) => ($b->mimeType === self::FOLDER) <=> ($a->mimeType === self::FOLDER)); 

and a $seen set keyed by file ID, so a file that was ticked twice is only sent once.

When nothing readable comes back, the error message explains the rule instead of saying "empty folder". That one message probably saves more support emails than anything else on the page.

Docs, Sheets and Slides have no bytes

Native Google files show up with MIME types like application/vnd.google-apps.document. There is no file to download, only an export to another format. I skip anything under application/vnd.google-apps. (shortcuts too), count how many were skipped, and tell the user at the end. Exporting to .docx and .xlsx is a separate feature for later.

Downloading without putting the token in a URL

Drive has no pre-signed download links. You GET /drive/v3/files/{id}?alt=media with a bearer token. The rest of my pipeline was built around plain URLs (WeTransfer and Dropbox both hand out signed links), so the Drive source returns the bare media URL and adds the token only at the moment it opens the stream:

return $this->httpClient->get($url, [ 'stream' => true, 'headers' => ['Authorization' => 'Bearer ' . $accessToken], ])->getBody(); 

The token never appears in a URL, so it never ends up in a log line.

Dropbox upload sessions, fed from a stream

On the Dropbox side, every file goes through an upload session, so the streamed path and the temp-file path share one loop: upload_session/start, then append_v2 per chunk, then finish with the destination path. Some details I'd want to know before writing it again:

  • Chunk size. Dropbox wants chunks in multiples of 4 MB, with at most 150 MB per request. I use 8 MB, which keeps memory low when several transfers run at once.
  • Retries can double-send a chunk. If a request times out after Dropbox actually received it, the retry gets a 409 incorrect_offset with the correct_offset Dropbox expects. If that is exactly offset + strlen($chunk), the chunk is already in, so carry on instead of failing:
 if ($response->status() === 409 && $response->json('error.correct_offset') === $offset + strlen($chunk)) { return; // Dropbox already has this chunk } 
  • A trailing space in a folder name fails at the very end. Dropbox rejects path segments ending in a space with path/malformed_path, but only at finish, after the whole file has gone up. I now trim every path segment before starting.
  • Check the length before you commit. If the source stream ends early, a short file would commit and look exactly like a delivered one. Comparing the bytes sent with the expected size before calling finish turns that into a clear error.
  • Space. users/get_space_usage gives allocated and used bytes, so the transfer can refuse up front when the files won't fit. A free Dropbox Basic account has 2 GB, so this comes up a lot. finish can still return insufficient_space if something else filled the account meanwhile, so that case gets its own friendly message too.

The result

From the user's side it is: sign in with Google, connect Dropbox, choose files and folders in Google's own picker, and press Transfer. The folder is rebuilt in Dropbox under its own name, and the app never sees the rest of their Drive. It is live at wetodrive.com/google-drive-to-dropbox, and the non-technical walkthrough is how to move files and folders from Google Drive to Dropbox.

If you have shipped something on drive.file and found a cleaner way around the folder-contents rule, I'd like to hear it.