Open lingyun-zhu opened 4 years ago
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?
Can you help add a snippet of code that is causing this?
@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();
}
}
Hello everyone i have same problem now how should i do to fix it? thx
Storage: com.google.cloud.storage.StorageException: Error writing request body to server #3410
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.