Когда я загружаю файлы, иногда они задерживаются на большом файле намного дольше, чем предполагалось. Он загружает предыдущие файлы нормально, но всегда зависает на этом файле размером 26 МБ. Загрузка должна занять всего 3 минуты, но она выполняется более 3 часов, использует максимальную пропускную способность загрузки в диспетчере задач и ошибки с 403 Unauthorized или «java.io.IOException: неожиданный конец потока» — просто случайные ошибки. Я загружаю в учетную запись службы Google, используя закрытый ключ. Я использую плагин Google Eclipse и добавил Drive API через плагин Eclipse. Единственное, что я могу придумать, это запустить его через прокси-сервер Fiddler2/4 для устранения неполадок, но мне не нужно этого делать.
Код
BufferedInputStream bis = new BufferedInputStream(new FileInputStream(f));
System.out.println("type of file "+f.getName()+":"+type + ", length:"+f.length());
File driveFile = DriveService.insertFile(name, type, Constants.DOC_TYPE_PRIMARY, bis);
public static File insertFile(String name, String type, String docType, InputStream inputStream) throws IOException, Exception
{
File file = new File();
file.setTitle(name);
file.setMimeType(type);
file.setDescription(docType);
List<ParentReference> parents = new ArrayList<ParentReference>(); //create parent ref
parents.add(new ParentReference().setId(Constants.DRIVE_FOLDER_IDS.get(docType)));
file.setParents(parents);
InputStreamContent isc = new InputStreamContent(type, inputStream);
File retval = getService().files().insert(file, isc).execute();
//apply domain reader access
enableDomainReaderAccess(retval.getId());
return retval;
}
Журнал
type of file MWV Soda Packaging Report_First Draft.pptx:null, length:26373917
Другие ошибки
Exception in thread "main" com.google.api.client.googleapis.json.GoogleJsonResponseException: 500 Internal Server Error
{
"code" : 500,
"errors" : [ {
"domain" : "global",
"message" : "Internal Error",
"reason" : "internalError"
} ],
"message" : "Internal Error"
}
at com.google.api.client.googleapis.json.GoogleJsonResponseException.from(GoogleJsonResponseException.java:145)
at com.google.api.client.googleapis.services.json.AbstractGoogleJsonClientRequest.newExceptionOnError(AbstractGoogleJsonClientRequest.java:113)
at com.google.api.client.googleapis.services.json.AbstractGoogleJsonClientRequest.newExceptionOnError(AbstractGoogleJsonClientRequest.java:40)
at com.google.api.client.googleapis.services.AbstractGoogleClientRequest.executeUnparsed(AbstractGoogleClientRequest.java:423)
at com.google.api.client.googleapis.services.AbstractGoogleClientRequest.executeUnparsed(AbstractGoogleClientRequest.java:343)
at com.google.api.client.googleapis.services.AbstractGoogleClientRequest.execute(AbstractGoogleClientRequest.java:460)
at com.mwv.pic.service.DriveService.insertFile(DriveService.java:167)
type of file Report Soda.ppt:application/vnd.openxmlformats-officedocument.presentationml.presentation, length:9103360
Exception in thread "main" java.io.IOException: insufficient data written
at sun.net.www.protocol.http.HttpURLConnection$StreamingOutputStream.close(HttpURLConnection.java:3213)
at com.google.api.client.http.javanet.NetHttpRequest.execute(NetHttpRequest.java:81)
at com.google.api.client.http.HttpRequest.execute(HttpRequest.java:964)
at com.google.api.client.googleapis.media.MediaHttpUploader.executeCurrentRequest(MediaHttpUploader.java:559)
at com.google.api.client.googleapis.media.MediaHttpUploader.resumableUpload(MediaHttpUploader.java:434)
at com.google.api.client.googleapis.media.MediaHttpUploader.upload(MediaHttpUploader.java:345)
at com.google.api.client.googleapis.services.AbstractGoogleClientRequest.executeUnparsed(AbstractGoogleClientRequest.java:418)
Версия
google-api-services-drive-v2-rev107-1.16.0-rc.jar