Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • Home
  • SEARCH
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 7177205
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 28, 20262026-05-28T16:39:50+00:00 2026-05-28T16:39:50+00:00

I am having the following code snippet to upload zip file without conversion to

  • 0

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.

enter image description here

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.

enter image description here

May I know, how I can overwrite file with same filename, during uploading to Google Doc?

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-28T16:39:51+00:00Added an answer on May 28, 2026 at 4:39 pm

    Here is how overwrite file works in Google Doc.

       // Rename and overwrite.
       documentListEntry.setTitle(new PlainTextConstruct(getGoogleDocTitle(checksum, date, version)));
       uploader = new ResumableGDataFileUploader.Builder(client, createUploadUrl, mediaFile, documentListEntry)
       .title(getGoogleDocTitle(checksum, date, version))
       .chunkSize(DEFAULT_CHUNK_SIZE).executor(executor)
       .trackProgress(listener, PROGRESS_UPDATE_INTERVAL).requestType(ResumableGDataFileUploader.RequestType.UPDATE)
       .build();
    

    To get a complete code snippet, please refer to saveToGoogleDoc utility function.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I am having the following code snippet in my application screen to show a
I'm having problems running the following code snippet using JavaScript and JQuery. listOfDisplayCategories is
I use the following code snippet to load data from google fusion table as
Good day. I am having the following code snippet in init.php. <?php include_once(config.php); include_once(__SITE_PATH
I m having the following code, however, I can see that the radio button
I am having following peice of code ,where in i am trying to serialize
Having sorted the tag_counts hash via the following code: sorted_tags = Contact.tag_counts.sort{ |x,y| x.name.downcase
I'm having an issue with the following code: private void DataPortal_Fetch(TaskCriteria criteria) { using
I'm having some problems with the following code: private class ClientPluginLoader : MarshalByRefObject {
I'm having troubles with the following code: <link type=text/css href=http://jqueryui.com/latest/themes/base/jquery.ui.all.css rel=stylesheet /> <script type=text/javascript

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.