I’m having trouble uploading certain file types to Google Drive through my C# application. My current implementation works perfectly when I upload text documents and Word files, but I keep running into issues with PDF and Excel files. Every time I attempt to upload these formats, I get a bad request error response from the API.
I’m using Single Sign-On authentication for Google login in my ASP.NET C# project. The authentication part works fine, and as I mentioned, some file types upload without any problems.
Has anyone encountered similar issues when working with PDF or Excel file uploads to Google Drive? I’m wondering if there are specific headers or parameters I need to set for these file types. Any guidance on how to handle different file formats during the upload process would be really helpful.
Thanks for any assistance you can provide!
i had a similar prob! make sure u set the right mimetypes for those file types when u upload. for pdfs use ‘application/pdf’ and for excel go with ‘application/vnd.openxmlformats-officedocument.spreadsheetml.sheet’. that worked for me!
This sounds like a file stream handling issue. I hit the same problem six months back while building a document management system. PDFs and Excel files are binary, so your stream’s probably getting corrupted during upload. Make sure you’re opening the file stream in binary mode - don’t apply any text encoding. Also check that your Content-Length header matches the actual file size. I found some PDFs were getting cut off because of bad stream handling. And make sure you’re disposing of the file stream properly after upload attempts - that can break future uploads.
Check your file size limits first - Google Drive API has different boundaries for different file types. Had this exact problem last year building a backup utility. Wasn’t actually the PDFs or Excel files - it was how I handled multipart upload requests. You need resumable uploads for larger files, not simple uploads. Most PDFs and Excel files go over the 5MB limit where simple uploads fail. Switch to resumable upload in the API and set proper chunk sizes. Also check if your file’s locked by another process before uploading - Excel files get sharing violations if they’re open somewhere else.