Мы используем Dropbox API v2 в нашем приложении для Android для загрузки файлов базы данных (.db) в папку пользователя Dropbox App.Ниже приведен код для загрузки файла:
InputStream inputStream = null;
FileMetadata obj = null;
try {
inputStream = new FileInputStream(dbFile);
obj = mDbxClient.files().uploadBuilder(remoteFilePath)
.withMode(WriteMode.OVERWRITE)
.uploadAndFinish(inputStream);
} catch (DbxException | IOException e) {
obj = null;
mException = e;
} finally {
if (inputStream != null)
try {
inputStream.close();
} catch (IOException e) {
e.printStackTrace();
}
}
Один и тот же файл загружается в быстрой последовательности 3-4 раза.Теперь все работает нормально, когда скорость интернета высокая (4G, Wifi), но когда пользователь переключается на сеть 2G / 3G, файл загружается не полностью.Вызывается метод обратного вызова onUploadComplete (), но размер файла здесь значительно уменьшился.Я приложил историю версий файла базы данных.https://www.dropbox.com/s/s7y43707ic1kqxg/dropbox.jpg?dl=0
Вы видите, что размер файла внезапно уменьшается до 104 КБ.Это становится поврежденным файлом базы данных.
Есть ли способ исправить это?Должен ли я изменить метод загрузки?(может быть, использовать UploadSession () или Вы не должны вызывать «Uploads» в быстрой последовательности?}
Ниже приведен журнал:
05-29 12:08:06.322 11232-11232/com.bk E/BKSync: upload starts
05-29 12:08:13.129 11232-11232/com.bk E/BKSync: upload ends
05-29 12:08:13.130 11232-11232/com.bk I/BKSync upload ends:: demo2_local.db size 692224 modified May 29, 2018 12:08:13 PM
05-29 12:08:13.471 11232-11232/com.bk E/BKSync: upload starts
05-29 12:08:22.992 11232-11232/com.bk E/BKSync: upload ends
05-29 12:08:22.993 11232-11232/com.bk I/BKSync upload ends:: demo2_local.db size 692224 modified May 29, 2018 12:08:23 PM
05-29 12:08:45.181 11232-11232/com.bk E/BKSync: upload starts
05-29 12:08:48.692 11232-11232/com.bk E/BKSync: upload starts
05-29 12:08:49.137 11232-11232/com.bk E/BKSync: upload starts
05-29 12:08:51.962 11232-11232/com.bk E/BKSync: upload starts
f05-29 12:09:24.183 11232-30020/com.bk E/BKSync: exception1
05-29 12:09:24.184 11232-30020/com.bk W/System.err: com.dropbox.core.NetworkIOException: Unable to resolve host "content.dropboxapi.com": No address associated with hostname
at com.dropbox.core.DbxUploader.finish(DbxUploader.java:235)
at com.dropbox.core.DbxUploader.uploadAndFinish(DbxUploader.java:106)
at com.dropbox.core.v2.DbxUploadStyleBuilder.uploadAndFinish(DbxUploadStyleBuilder.java:92)
05-29 12:09:24.185 11232-30020/com.bk W/System.err: at com.bk.DropboxUploadFileTask.doInBackground(DropboxUploadFileTask.java:81)
at com.bkbk.DropboxUploadFileTask.doInBackground(DropboxUploadFileTask.java:20)
at android.os.AsyncTask$2.call(AsyncTask.java:304)
at java.util.concurrent.FutureTask.run(FutureTask.java:237)
at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1133)
at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:607)
at java.lang.Thread.run(Thread.java:762)
05-29 12:09:24.189 11232-30020/com.bk W/System.err: Caused by: java.net.UnknownHostException: Unable to resolve host "content.dropboxapi.com": No address associated with hostname
at java.net.Inet6AddressImpl.lookupHostByName(Inet6AddressImpl.java:125)
at java.net.Inet6AddressImpl.lookupAllHostAddr(Inet6AddressImpl.java:74)
at java.net.InetAddress.getAllByName(InetAddress.java:752)
at okhttp3.Dns$1.lookup(Dns.java:39)
at okhttp3.internal.connection.RouteSelector.resetNextInetSocketAddress(RouteSelector.java:185)
at okhttp3.internal.connection.RouteSelector.nextProxy(RouteSelector.java:149)
at okhttp3.internal.connection.RouteSelector.next(RouteSelector.java:84)
05-29 12:09:24.190 11232-30020/com.bk W/System.err: at okhttp3.internal.connection.StreamAllocation.findConnection(StreamAllocation.java:213)
at okhttp3.internal.connection.StreamAllocation.findHealthyConnection(StreamAllocation.java:134)
at okhttp3.internal.connection.StreamAllocation.newStream(StreamAllocation.java:113)
at okhttp3.internal.connection.ConnectInterceptor.intercept(ConnectInterceptor.java:42)
at okhttp3.internal.http.RealInterceptorChain.proceed(RealInterceptorChain.java:147)
at okhttp3.internal.http.RealInterceptorChain.proceed(RealInterceptorChain.java:121)
05-29 12:09:24.193 11232-30020/com.bk W/System.err: at okhttp3.internal.cache.CacheInterceptor.intercept(CacheInterceptor.java:93)
at okhttp3.internal.http.RealInterceptorChain.proceed(RealInterceptorChain.java:147)
05-29 12:09:24.194 11232-30020/com.bk W/System.err: at okhttp3.internal.http.RealInterceptorChain.proceed(RealInterceptorChain.java:121)
at okhttp3.internal.http.BridgeInterceptor.intercept(BridgeInterceptor.java:93)
05-29 12:09:24.195 11232-30020/com.bk W/System.err: at okhttp3.internal.http.RealInterceptorChain.proceed(RealInterceptorChain.java:147)
at okhttp3.internal.http.RetryAndFollowUpInterceptor.intercept(RetryAndFollowUpInterceptor.java:125)
at okhttp3.internal.http.RealInterceptorChain.proceed(RealInterceptorChain.java:147)
at okhttp3.internal.http.RealInterceptorChain.proceed(RealInterceptorChain.java:121)
at okhttp3.RealCall.getResponseWithInterceptorChain(RealCall.java:200)
at okhttp3.RealCall$AsyncCall.execute(RealCall.java:147)
at okhttp3.internal.NamedRunnable.run(NamedRunnable.java:32)
... 3 more
05-29 12:09:24.196 11232-30020/com.bk W/System.err: Caused by: android.system.GaiException: android_getaddrinfo failed: EAI_NODATA (No address associated with hostname)
at libcore.io.Posix.android_getaddrinfo(Native Method)
at libcore.io.ForwardingOs.android_getaddrinfo(ForwardingOs.java:55)
at java.net.Inet6AddressImpl.lookupHostByName(Inet6AddressImpl.java:106)
... 26 more
05-29 12:09:24.211 11232-11232/com.bk E/BKSync: upload ends
Failed to upload file.
05-29 12:09:24.300 11232-11232/com.bk E/BKSync: upload starts
05-29 12:09:24.314 11232-30020/com.bk E/BKSync: exception1
05-29 12:09:24.315 11232-30020/com.bk W/System.err: com.dropbox.core.NetworkIOException: Pipe closed
at com.dropbox.core.DbxUploader.uploadAndFinish(DbxUploader.java:103)
at com.dropbox.core.v2.DbxUploadStyleBuilder.uploadAndFinish(DbxUploadStyleBuilder.java:92)
at com.bk.DropboxUploadFileTask.doInBackground(DropboxUploadFileTask.java:81)
at com.bk.DropboxUploadFileTask.doInBackground(DropboxUploadFileTask.java:20)
at android.os.AsyncTask$2.call(AsyncTask.java:304)
at java.util.concurrent.FutureTask.run(FutureTask.java:237)
at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1133)
at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:607)
05-29 12:09:24.316 11232-30020/com.bk W/System.err: at java.lang.Thread.run(Thread.java:762)
Caused by: com.dropbox.core.util.IOUtil$WriteException: Pipe closed
at com.dropbox.core.util.IOUtil.copyStreamToStream(IOUtil.java:61)
at com.dropbox.core.util.IOUtil.copyStreamToStream(IOUtil.java:68)
at com.dropbox.core.util.IOUtil.copyStreamToStream(IOUtil.java:43)
at com.dropbox.core.http.HttpRequestor$Uploader.upload(HttpRequestor.java:98)
at com.dropbox.core.DbxUploader.uploadAndFinish(DbxUploader.java:98)
... 8 more
05-29 12:09:24.318 11232-30020/com.bk W/System.err: Caused by: java.io.IOException: Pipe closed
at java.io.PipedInputStream.checkStateForReceive(PipedInputStream.java:267)
at java.io.PipedInputStream.receive(PipedInputStream.java:233)
at java.io.PipedOutputStream.write(PipedOutputStream.java:149)
at com.dropbox.core.util.IOUtil.copyStreamToStream(IOUtil.java:59)
... 12 more
05-29 12:09:24.441 11232-11232/com.bk E/BKSync: upload ends
05-29 12:09:24.442 11232-11232/com.bk E/BKSync: Failed to upload file.
com.dropbox.core.NetworkIOException: Pipe closed
at com.dropbox.core.DbxUploader.uploadAndFinish(DbxUploader.java:103)
at com.dropbox.core.v2.DbxUploadStyleBuilder.uploadAndFinish(DbxUploadStyleBuilder.java:92)
at com.bk.DropboxUploadFileTask.doInBackground(DropboxUploadFileTask.java:81)
at com.bk.DropboxUploadFileTask.doInBackground(DropboxUploadFileTask.java:20)
at android.os.AsyncTask$2.call(AsyncTask.java:304)
at java.util.concurrent.FutureTask.run(FutureTask.java:237)
at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1133)
at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:607)
at java.lang.Thread.run(Thread.java:762)
Caused by: com.dropbox.core.util.IOUtil$WriteException: Pipe closed
at com.dropbox.core.util.IOUtil.copyStreamToStream(IOUtil.java:61)
at com.dropbox.core.util.IOUtil.copyStreamToStream(IOUtil.java:68)
at com.dropbox.core.util.IOUtil.copyStreamToStream(IOUtil.java:43)
at com.dropbox.core.http.HttpRequestor$Uploader.upload(HttpRequestor.java:98)
at com.dropbox.core.DbxUploader.uploadAndFinish(DbxUploader.java:98)
at com.dropbox.core.v2.DbxUploadStyleBuilder.uploadAndFinish(DbxUploadStyleBuilder.java:92)
at com.bk.DropboxUploadFileTask.doInBackground(DropboxUploadFileTask.java:81)
at com.bk.DropboxUploadFileTask.doInBackground(DropboxUploadFileTask.java:20)
at android.os.AsyncTask$2.call(AsyncTask.java:304)
at java.util.concurrent.FutureTask.run(FutureTask.java:237)
at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1133)
at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:607)
at java.lang.Thread.run(Thread.java:762)
Caused by: java.io.IOException: Pipe closed
at java.io.PipedInputStream.checkStateForReceive(PipedInputStream.java:267)
at java.io.PipedInputStream.receive(PipedInputStream.java:233)
at java.io.PipedOutputStream.write(PipedOutputStream.java:149)
at com.dropbox.core.util.IOUtil.copyStreamToStream(IOUtil.java:59)
at com.dropbox.core.util.IOUtil.copyStreamToStream(IOUtil.java:68)
at com.dropbox.core.util.IOUtil.copyStreamToStream(IOUtil.java:43)
at com.dropbox.core.http.HttpRequestor$Uploader.upload(HttpRequestor.java:98)
at com.dropbox.core.DbxUploader.uploadAndFinish(DbxUploader.java:98)
at com.dropbox.core.v2.DbxUploadStyleBuilder.uploadAndFinish(DbxUploadStyleBuilder.java:92)
at com.bk.DropboxUploadFileTask.doInBackground(DropboxUploadFileTask.java:81)
at com.bk.DropboxUploadFileTask.doInBackground(DropboxUploadFileTask.java:20)
at android.os.AsyncTask$2.call(AsyncTask.java:304)
at java.util.concurrent.FutureTask.run(FutureTask.java:237)
at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1133)
at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:607)
at java.lang.Thread.run(Thread.java:762)
Как вы видите, исключения возникают из-за приложения. Проблема возникает, когда пользователь начинает загрузку на 4G, а затем из-за входящего вызова переключает сеть3G. Размер файла в Dropbox резко уменьшается.
Пожалуйста, помогите.