I’m building a desktop app in Python and need help with the Google Drive API. I want to make a new directory in my Drive account but I’m stuck on how to do this properly. I looked at the Files insert method in the documentation but it seems like it’s only for uploading files that already exist on my local machine. What’s the correct way to create a directory instead of uploading a file? Also, I’m curious about the MediaFileUpload function - what exactly does it do and can the Google Drive API be used to create different file types programmatically?
to make a folder, use files().create() with the mime type as ‘application/vnd.google-apps.folder’. don’t worry about MediaFileUpload for folders, it’s mainly for actual files. hope this helps!
Creating directories through the API stumped me at first. Here’s what I learned: folders in Google Drive are just files with a special MIME type. When you use files().create(), set the name and use mimeType: ‘application/vnd.google-apps.folder’. Don’t use MediaFileUpload for this - that’s only for uploading actual files from your computer. MediaFileUpload handles large files well with resumable uploads if your connection cuts out. You can create other Google Workspace files the same way - just use ‘application/vnd.google-apps.document’ for Docs or ‘application/vnd.google-apps.spreadsheet’ for Sheets.
Yeah, Files insert is deprecated now. Use files().create() instead like Mike71 mentioned, but here’s what you actually need to do. Set the body parameter with your folder name and use ‘application/vnd.google-apps.folder’ as the mimeType. Want it inside another folder? Just add the parent folder ID to the parents field. MediaFileUpload handles the actual file content when you’re uploading stuff to Drive. It reads your local file and manages uploads, including resumable ones for big files. The Drive API can create Google Docs, Sheets, Slides - whatever - just use their specific mimeTypes. You’ll start with blank documents though, not upload existing content.