Service Unavailable error during multipart file upload to Google Drive API v2

I’m encountering a 503 ‘Service Unavailable’ error while attempting to upload files using multipart requests through the Google Drive API v2. The response comes back empty with specific headers indicating a server issue.

Response headers I’m receiving:

{'content-length': '0', 'x-google-cache-control': 'remote-fetch', 'expires': 'Mon, 15 Jan 1990 00:00:00 GMT', 'server': 'HTTP Upload Server Built on Jul 22 2012 14:30:15 (1342980615)', 'via': 'HTTP/1.1 GWA', 'pragma': 'no-cache', 'cache-control': 'no-cache, no-store, must-revalidate', 'date': 'Wed, 18 Jul 2012 15:45:30 GMT', 'content-type': 'text/html; charset=UTF-8'}

My multipart request structure:

POST /upload/drive/v2/files?uploadType=multipart

Authorization: Bearer <token>
Content-Length: <size>
Content-Type: multipart/related; boundary="<encoded_boundary_string>"

--<encoded_boundary_string>
Content-Type: application/json

{"title": "document.pdf", "mimeType":"application/pdf", "parents":[]}
--<encoded_boundary_string>
Content-Type: application/pdf
Content-Transfer-Encoding: base64

<base64_file_content>
--<encoded_boundary_string>--

I can work around this by creating metadata first, then updating with media content separately, but I’d prefer avoiding multiple API calls. Is there something incorrect in my multipart format or approach?

check ur content-length calculation - that’s usually what causes 503s on multipart uploads. if ur calculated size doesn’t match the actual body size, Google’s servers will reject it. also, that 2012 server timestamp in ur headers looks suspicious. u might be hitting a cached error response.

I’ve hit this exact issue with Drive API v2 multipart uploads. Nine times out of ten, it’s the boundary encoding that’s screwing things up. Your request looks fine, but check that your boundary string doesn’t have any weird characters that mess with encoding. Also watch out for extra line breaks or spaces when you’re building the multipart body - the API’s picky as hell about formatting. Those 503 errors with server timestamps? Sometimes it’s just Google’s servers having a bad day, not your code. I’d add exponential backoff retry logic since these errors come and go. If it keeps happening, just switch to resumable uploads instead - they’re way more reliable for bigger files and handle Google’s server hiccups better.

That empty response with cache headers screams gateway timeout, not a direct API error. I’ve hit this exact issue when multipart uploads get too big on Drive API v2. That 2012 server timestamp? You’re probably hitting an ancient load balancer that can’t handle the request size or processing time. Break your base64 content into smaller chunks or just use the resumable upload endpoint. Also check if your OAuth token expired mid-request - I’ve seen that cause this same 503 pattern. Your multipart format looks fine, but Drive API v2 just sucks with large payloads in multipart mode.