I'm trying to upload a file to Google Docs/Drive using Documents List API on Android.
The problem is that it seems to be OK (I get status code 200, OK), but the file doesn't show up when looking at my documents. Uploading to this address that I get when listing the feeds: https://docs.google.com/feeds/upload/create-session/default/private/full?convert=false
I've tried several ways, but w/o any luck for example:
File file = new File(sFile); // Path to the file on the SD card
InputStreamContent content = new InputStreamContent("application/vnd.mymimetype",
new BufferedInputStream(new FileInputStream(file)));
content.setLength(file.length());
HttpRequest request = transport.createRequestFactory().buildPostRequest(new GoogleUrl(sURL), content); // Urls is https://docs.google.com/feeds/upload/create-session/default/private/full?convert=false
GoogleHeaders headers = getDefaultHeaders(); // Set version 3 and authentication
request.setHeaders(headers);
res = request.execute(); // Will have status code 200, not 201 as created and no entity returned?
I've also tried with MediaUploader, but same result (In this example, I set metadata, but I think I get an exception that Content Lenght isn't set, so in my working example, I don't set meta data):
StringBuilder sAtom = new StringBuilder()
.append("<?xml version='1.0' encoding='UTF-8'?>")
.append("<entry xmlns=\"http://www.w3.org/2005/Atom\" xmlns:docs=\"http://schemas.google.com/docs/2007\">")
.append("<title>THeFile</title>").append("</entry>");
String sCmd = sAtom.toString();
InputStream inStream = null;
inStream = new ByteArrayInputStream(sCmd.getBytes("UTF-8"));
final InputStreamContent oContent = new InputStreamContent("application/atom+xml", inStream);
oContent.setLength(sCmd.length());
InputStreamContent mediaContent = new InputStreamContent("application/vnd.mymimetype",
new BufferedInputStream(new FileInputStream(file)));
mediaContent.setLength(file.length());
MediaHttpUploader uploader = new MediaHttpUploader(mediaContent, transport, new HttpRequestInitializer() {
@Override
public void initialize(HttpRequest request) throws IOException {
GoogleHeaders headers = getDefaultHeaders();
headers.setSlug("thefile.mab");
request.setHeaders(headers);
}
});
uploader.setMetadata(oContent);
MediaHttpUploaderProgressListener listner = new CustomProgressListener();
uploader.setProgressListener(listner);
uploader.setDirectUploadEnabled(true);
HttpResponse response = uploader.upload(new GoogleUrl(sURL));
if (!response.isSuccessStatusCode()) { // Gets that the upload was successful
throw new Exception("Error");
}
What am I missing?? :/