I am developing GAE java app and i need to upload PDF file into user’s google drive, but upload always fails and i don`t know what could be wrong as i checked few code samples already.
import com.google.api.services.drive.Drive;
import com.google.api.services.drive.model.File;
.
.
.
byte[] pdfContent = <... 52kb PDF file ...>
ByteArrayContent mediaContent = new ByteArrayContent("application/pdf", pdfContent);
File myPDF = new File();
myPDF.setTitle("Sample PDF");
myPDF.setDescription("Sample PDF");
Drive driveService = new Drive.Builder(HTTP_TRANSPORT, JSON_FACTORY, getStoredCredential()).build();
Drive.Files.Insert insert = driveService.files().insert(hugePDF, mediaContent);
insert.getMediaHttpUploader().setChunkSize(1024 * 1024);
File file = insert.execute();
This upload code always gets Error: 400 OK
{
"error": {
"errors": [
{
"domain": "global",
"reason": "badRequest",
"message": "Bad Request"
}
],
"code": 400,
"message": "Bad Request"
}
}
I am using Google drive library : google-api-services-drive-v2-rev1-1.7.2-beta.jar
Credentials are fine as i am able to list or download files from user`s google drive.
I think that the problem is in your library version. Current version is v2-rev39-1.12.0-beta. Check http://code.google.com/p/google-api-java-client/wiki/APIs#Drive_API. It is always better to use last API library version. We had a lot of problems with BigQuery API when we missed one update.