I am having the following code snippet to upload zip file without conversion to Google Doc.
package sample.docs;
import com.google.gdata.client.docs.*;
import com.google.gdata.data.docs.*;
import com.google.gdata.util.*;
import java.io.IOException;
import java.net.MalformedURLException;
import com.google.gdata.client.media.ResumableGDataFileUploader;
import com.google.gdata.client.uploader.FileUploadData;
import com.google.gdata.client.uploader.ProgressListener;
import com.google.gdata.client.uploader.ResumableHttpFileUploader;
import com.google.gdata.data.media.MediaFileSource;
import java.io.File;
import java.net.URL;
import java.util.concurrent.CountDownLatch;
import java.util.concurrent.ExecutorService;
import java.util.concurrent.Executors;
import java.util.concurrent.TimeUnit;
public class DocumentListDemo {
private static class FileUploadProgressListener implements ProgressListener {
final CountDownLatch countDownLatch = new CountDownLatch(1);
@Override
public synchronized void progressChanged(ResumableHttpFileUploader uploader)
{
final String fileId = ((FileUploadData) uploader.getData()).getFileName();
switch(uploader.getUploadState()) {
case COMPLETE:
case CLIENT_ERROR:
countDownLatch.countDown();
System.out.println(fileId + ": Completed");
break;
case IN_PROGRESS:
System.out.println(fileId + ":" + String.format("%3.0f", uploader.getProgress() * 100) + "%");
break;
case NOT_STARTED:
System.out.println(fileId + ":" + "Not Started");
break;
}
}
public void await() throws InterruptedException {
countDownLatch.await();
}
}
public static void main(String[] args) throws MalformedURLException, IOException, ServiceException, InterruptedException, DocumentListException {
int MAX_CONCURRENT_UPLOADS = 10;
int PROGRESS_UPDATE_INTERVAL = 1000;
int DEFAULT_CHUNK_SIZE = 10485760;
DocsService client = new DocsService("JStock");
client.setUserCredentials("yancheng.cheok@gmail.com", "this-is-my-password");
// Create a listener
FileUploadProgressListener listener = new FileUploadProgressListener();
// Pool for handling concurrent upload tasks
ExecutorService executor = Executors.newFixedThreadPool(MAX_CONCURRENT_UPLOADS);
File file = new File("c:\\Pictures.zip");
String contentType = DocumentListEntry.MediaType.fromFileName(file.getName()).getMimeType();
MediaFileSource mediaFile = new MediaFileSource(file, contentType);
URL createUploadUrl = new URL("https://docs.google.com/feeds/upload/create-session/default/private/full");
ResumableGDataFileUploader uploader = new ResumableGDataFileUploader.Builder(client, createUploadUrl, mediaFile, null)
.title(mediaFile.getName())
.chunkSize(DEFAULT_CHUNK_SIZE).executor(executor)
.trackProgress(listener, PROGRESS_UPDATE_INTERVAL)
.build();
uploader.start();
// Wait for completion.
listener.await();
// Thread clean up.
executor.shutdownNow();
executor.awaitTermination(Long.MAX_VALUE, TimeUnit.DAYS);
System.out.println("done!");
}
}
To compile the above code, the following 4 libraries are required.

However, I realize, when I try to upload file with same filename again and again, the previous uploaded file will not be overwritten.
This is the outcome if I execute the above code for 4 times.

May I know, how I can overwrite file with same filename, during uploading to Google Doc?
Here is how overwrite file works in Google Doc.
To get a complete code snippet, please refer to saveToGoogleDoc utility function.