Error loading large file upload to Google Drive

I am creating small applications from this user that can upload their MS Office file to their registered G_Drive email ID on an Android device. and export this file as a PDF.

To do this, I received a help form below the link:

https://developers.google.com/drive/v2/reference/files/insert#examples

https://developers.google.com/drive/manage-downloads#downloading_google_documents

i created the application and its working tone for a small file (<1MB), but when I send a large size to g_Drive, I get the following errors:

java.io.exception Unexpected End of Stream java.net.SocketTimeoutException: Read timed out 

I tried for renewable download, but the insert method has no option to install it. if I set the download type to resume using

 service.files().insert(body, mediaContent).set("upload type", "resumable"); 

or

 Insert insertService = service.files().insert(body, mediaContent).setConvert(true); insertService.getMediaHttpUploader().setDirectUploadEnabled(false); insertService.getMediaHttpUploader().setChunkSize(MediaHttpUploader.DEFAULT_CHUNK_SIZE); file = insertService.execute(); 

and also generates the same errors.

same download case too .....

send me some solutions ... for this ...

+3
source share
1 answer

Do not use basic downloads for files larger than 5 MB.

Before downloading, you must set the length of the content of the media content. Otherwise, it is likely that the Google endpoint will not be able to recognize that the download is complete, and it will wait until the socket is disconnected.

 InputStreamContent mediaContent = new InputStreamContent("image/jpeg", new BufferedInputStream( new FileInputStream(UPLOAD_FILE))); mediaContent.setLength(UPLOAD_FILE.length()); Insert insert = drive.files().insert(fileMetadata, mediaContent); MediaHttpUploader uploader = insert.getMediaHttpUploader(); uploader.setDirectUploadEnabled(false); uploader.setProgressListener(new FileUploadProgressListener()); insert.execute(); 

On the site [1] there is a full version for downloading based on Android.

+1
source

Source: https://habr.com/ru/post/1257763/


All Articles