I have an application that utilizes the Google Docs API for uploading files. Until recently, everything was functioning smoothly, but I am now encountering a 503 error when attempting to upload files.
The process is as follows: initially, I create a session that provides a resumable URL (this part still works correctly). However, when I attempt to send the file contents to that URL, a 503 Service Unavailable error occurs.
Here’s how my code looks for uploading the file:
URL uploadFileUrl = new URL(resumableUploadUrl);
HttpURLConnection httpConnection = (HttpURLConnection) uploadFileUrl.openConnection();
httpConnection.addRequestProperty("client_id", OAuth2Client.CLIENT_ID);
httpConnection.addRequestProperty("client_secret", OAuth2Client.CLIENT_SECRET);
httpConnection.setRequestProperty("Authorization", "OAuth " + GetAuthToken());
httpConnection.setRequestProperty("X-Upload-Content-Length", String.valueOf(fileContents.length()));
httpConnection.setRequestProperty("X-Upload-Content-Type", "text/xml");
httpConnection.setRequestProperty("Content-Type", "text/xml");
httpConnection.setRequestProperty("Content-Length", String.valueOf(fileContents.length()));
httpConnection.setRequestProperty("Slug", fileName);
if(isUpdate)
{
httpConnection.setRequestProperty("If-Match", "*");
httpConnection.setRequestMethod("PUT");
}
else
{
httpConnection.setRequestMethod("POST");
}
httpConnection.setRequestProperty("GData-Version", "3.0");
httpConnection.setRequestProperty("User-Agent", "YourAppName");
httpConnection.setUseCaches(false);
httpConnection.setDoInput(true);
httpConnection.setDoOutput(true);
DataOutputStream dataOutputStream = new DataOutputStream(httpConnection.getOutputStream());
dataOutputStream.writeBytes(fileContents);
dataOutputStream.flush();
dataOutputStream.close();
int responseCode = httpConnection.getResponseCode();
String newLocation = httpConnection.getHeaderField("location");
This code is used for both initiating the upload session and for sending the file data. I haven’t modified my code in over a year. Is it possible that recent changes to the API could be causing this issue?