Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Problems uploading files to google drive: java.io.IOException: Error writing request body to server #1526

Open
lingyun-zhu opened this issue May 15, 2020 · 4 comments
Labels
api: drive Issues related to the Drive API API. needs more info This issue needs more information from the customer to proceed. priority: p4 type: question Request for information or clarification. Not an issue.

Comments

@lingyun-zhu
Copy link

lingyun-zhu commented May 15, 2020

Storage: com.google.cloud.storage.StorageException: Error writing request body to server #3410

Caused by: java.io.IOException: Error writing request body to server
    at sun.net.www.protocol.http.HttpURLConnection$StreamingOutputStream.checkError(HttpURLConnection.java:3593)
    at sun.net.www.protocol.http.HttpURLConnection$StreamingOutputStream.write(HttpURLConnection.java:3576)
    at java.io.BufferedOutputStream.flushBuffer(BufferedOutputStream.java:82)
    at java.io.BufferedOutputStream.write(BufferedOutputStream.java:126)
    at java.util.zip.DeflaterOutputStream.deflate(DeflaterOutputStream.java:253)
    at java.util.zip.DeflaterOutputStream.write(DeflaterOutputStream.java:211)
    at java.util.zip.GZIPOutputStream.write(GZIPOutputStream.java:145)
    at com.google.api.client.util.ByteStreams.copy(ByteStreams.java:53)
    at com.google.api.client.util.IOUtils.copy(IOUtils.java:87)
    at com.google.api.client.http.AbstractInputStreamContent.writeTo(AbstractInputStreamContent.java:67)
    at com.google.api.client.http.GZipEncoding.encode(GZipEncoding.java:50)
    at com.google.api.client.http.HttpEncodingStreamingContent.writeTo(HttpEncodingStreamingContent.java:48)
    at com.google.api.client.http.javanet.NetHttpRequest$DefaultOutputWriter.write(NetHttpRequest.java:76)
    at com.google.api.client.http.javanet.NetHttpRequest.writeContentToOutputStream(NetHttpRequest.java:171)
    at com.google.api.client.http.javanet.NetHttpRequest.execute(NetHttpRequest.java:117)
    at com.google.api.client.http.javanet.NetHttpRequest.execute(NetHttpRequest.java:84)
    at com.google.api.client.http.HttpRequest.execute(HttpRequest.java:1012)
    at com.google.api.client.googleapis.media.MediaHttpUploader.executeCurrentRequestWithoutGZip(MediaHttpUploader.java:551)
    at com.google.api.client.googleapis.media.MediaHttpUploader.executeCurrentRequest(MediaHttpUploader.java:568)
    at com.google.api.client.googleapis.media.MediaHttpUploader.resumableUpload(MediaHttpUploader.java:422)
    at com.google.api.client.googleapis.media.MediaHttpUploader.upload(MediaHttpUploader.java:336)
    at com.google.api.client.googleapis.services.AbstractGoogleClientRequest.executeUnparsed(AbstractGoogleClientRequest.java:551)
    at com.google.api.client.googleapis.services.AbstractGoogleClientRequest.executeUnparsed(AbstractGoogleClientRequest.java:475)
    at com.google.api.client.googleapis.services.AbstractGoogleClientRequest.execute(AbstractGoogleClientRequest.java:592)
    ... 48 common frames omitted

In others places(google-cloud-java ) , google api added a retry to successfully solved this problem.
So I want to know if this error could be solved by add a similar retry? thank you.

@lingyun-zhu
Copy link
Author

at com.google.api.client.util.ByteStreams.copy(ByteStreams.java:53)

at com.google.api.client.googleapis.media.MediaHttpUploader.executeCurrentRequestWithoutGZip(MediaHttpUploader.java:551)

It seems that something went wrong.The problem with googleapi like this, (this time is MediaHttpUploader) Is there any solution to the problem?

@lingyun-zhu lingyun-zhu reopened this May 15, 2020
@lingyun-zhu lingyun-zhu changed the title java.io.IOException: Error writing request body to server(google1.34.2) Problems uploading files to Cloud Storage: com.google.cloud.storage.StorageException: Error writing request body to server May 15, 2020
@yoshi-automation yoshi-automation added triage me I really want to be triaged. 🚨 This issue needs some love. labels May 16, 2020
@chingor13 chingor13 added api: storage Issues related to the Cloud Storage API. type: question Request for information or clarification. Not an issue. labels May 21, 2020
@chingor13
Copy link
Collaborator

Can you help add a snippet of code that is causing this?

@chingor13 chingor13 added the needs more info This issue needs more information from the customer to proceed. label May 21, 2020
@yoshi-automation yoshi-automation removed triage me I really want to be triaged. 🚨 This issue needs some love. labels May 21, 2020
@lingyun-zhu lingyun-zhu changed the title Problems uploading files to Cloud Storage: com.google.cloud.storage.StorageException: Error writing request body to server Problems uploading files to Cloud Storage: com.google.google.drive.StorageException: Error writing request body to server May 22, 2020
@lingyun-zhu lingyun-zhu changed the title Problems uploading files to Cloud Storage: com.google.google.drive.StorageException: Error writing request body to server Problems uploading files to google drive: java.io.IOException: Error writing request body to server May 22, 2020
@lingyun-zhu
Copy link
Author

lingyun-zhu commented May 22, 2020

@chingor13
Thank you for your prompt reply.
I tried with the following code to upload file to Google Drive by using inputStream.
The result is successful upload in most cases,but occasionally failed with
java.io.IOException: Error writing request body to server.
it seems like this issue google-cloud-java:StorageException: Error writing request body to server #3410

Code Snippet:


public class CreateDocument {                                                                                                   
	private static final String APP_NAME = "Dummy APP";                                                                                                    
	private static final JsonFactory JSON_FACTORY = JacksonFactory.getDefaultInstance();                                                                                                     
	private String folderId;                                                                                                  
	private InputStream inputStream;                                                                                                            
	private HttpTransport HTTP_TRANSPORT;                                                                                                            

	public String execute(String accessToken) throws Exception {                                                                                                       
		Drive driveService = createGDriveService(accessToken);                                                                                                 
		File fileMetadata = getFileMetadata(); //MimeType is "application/pdf"
		BufferedInputStream bufferedInputStream = new BufferedInputStream(inputStream);                                                                                                    
		InputStreamContent mediaContent = new InputStreamContent(fileMetadata.getMimeType(), bufferedInputStream);                                                                                                  
		Drive.Files.Create request;                                                                                                          

		request = driveService.files().create(fileMetadata, mediaContent);                                                                                                            
		request.setFields("*");                                                                                                  
		request.setSupportsAllDrives(true);
		//[IOException: Error writing request body to server] is happened when i run execute()
		//file upload is success in most cases but occasionally failed
		File response = request.execute(); 

		return response.getId();                                                                                                
	}                                                                                                              

	public Drive createGDriveService(String accessToken) throws Exception {                                                                                                               
		SimpleHttpInitializer initializer = new SimpleHttpInitializer(accessToken); //READ_TIMEOUT is 3 minutes,CONNECT_TIMEOUT is also 3 minutes
		return new Drive.Builder(HTTP_TRANSPORT, JSON_FACTORY, initializer).setApplicationName(APP_NAME).build();                                                                                                        
	}                                                                                                              
}                                                                                                              

@bakazhou
Copy link

Hello everyone
i have same problem now
how should i do to fix it?
thx

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
api: drive Issues related to the Drive API API. needs more info This issue needs more information from the customer to proceed. priority: p4 type: question Request for information or clarification. Not an issue.
Projects
None yet
Development

No branches or pull requests

6 participants