I’m facing an issue while trying to upload PDF files to Google Docs using Java. Specifically, I encounter an error with FileUploadProgressListener, and I’m unsure whether it’s a Google API component or if I should create a custom class.
Here’s the code snippet I am using:
int MAX_UPLOADS = 10;
int PROGRESS_INTERVAL = 1000;
int CHUNK_SIZE = 10485760;
ExecutorService uploadPool = Executors.newFixedThreadPool(MAX_UPLOADS);
File pdf = new File(filePath);
String mimeType = DocumentListEntry.MediaType.fromFileName(pdf.getName()).getMimeType();
String contentType = DocumentListEntry.MediaType.fromFileName(pdf.getName()).getMimeType();
MediaFileSource mediaSource = new MediaFileSource(pdf, contentType);
URL uploadUrl = new URL("https://drive.google.com/feeds/upload/create-session/default/private/full");
FileUploadProgressListener progressListener = new FileUploadProgressListener();
ResumableGDataFileUploader uploader = new ResumableGDataFileUploader(uploadUrl, mediaSource, service, CHUNK_SIZE, uploadPool, progressListener, PROGRESS_INTERVAL);
The FileUploadProgressListener is producing an error. Could anyone assist me in figuring out what I am doing wrong? Should I implement this class myself, or is it included in the Google API?
The error arises because FileUploadProgressListener is not part of the Google API, and you must implement it yourself. Based on my experience, you should create a custom class that implements this listener and override necessary methods like onProgress() or progressChanged(), which report upload progress. Additionally, the code provided utilizes the deprecated GData API. It’s advisable to transition to Google Drive API v3 for improved file upload handling and support for resumable uploads using more up-to-date service methods.
I encountered a similar issue while working with the Google Drive API. It’s important to note that FileUploadProgressListener is not provided as part of the API; you need to implement it yourself. This interface allows you to monitor the upload progress of files.
To resolve your issue, create a custom class that implements this interface and override methods like progressChanged() for tracking the status of uploads. Be aware that your current implementation seems to utilize the deprecated GData API. For new projects, I strongly recommend transitioning to the latest Google Drive API v3, which offers improved documentation and a more straightforward approach to file uploads.
you prob missed implementing the FileUploadProgressListener. google doesn’t include it, so u gotta write that class urself to manage the progress. also, just a heads up, gdata is kinda old now, switching to the newer Drive API could save you some headaches!