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

File downloaded no fully #106

Open
Rehckover opened this issue Aug 28, 2017 · 1 comment
Open

File downloaded no fully #106

Rehckover opened this issue Aug 28, 2017 · 1 comment

Comments

@Rehckover
Copy link

I try to dowload file with size 3.7MB and often receives onComplete while actual file size is 122kb or 50kb. Can you help with this?
My link is: https://doc-0g-4k-docs.googleusercontent.com/docs/securesc/f6a1d72cge9p0eq8mkjrughdsskulo18/gqbs46o1bts8v2mn4sv312fk30oavn7s/1503914400000/04284872070643305544/04284872070643305544/0B6e1WFHf4jrKdXFiQ0d6dEZ3WEE?e=download

My code is:

  public void downloadFile(String url) {
       Uri downloadUri = Uri.parse(url);
       File destinationFolder = context.getExternalCacheDir();
       assert destinationFolder != null;
       Uri destinationUri = Uri.parse(destinationFolder.getAbsolutePath()
               + "/"
               + "depth.apk");
       DownloadRequest downloadRequest = new DownloadRequest(downloadUri)
               .setRetryPolicy(new DefaultRetryPolicy())
               .setDestinationURI(destinationUri).setPriority(DownloadRequest.Priority.HIGH)
               .setStatusListener(new DownloadStatusListenerV1() {
                   @Override
                   public void onDownloadComplete(DownloadRequest downloadRequest) {
                       Log.d(TAG, "onDownloadComplete: ");
                   }

                   @Override
                   public void onDownloadFailed(DownloadRequest downloadRequest, int errorCode, String errorMessage) {
                       Log.d(TAG, "onDownloadFailed: " + errorCode + " : " + errorMessage);
                   }

                   @Override
                   public void onProgress(DownloadRequest downloadRequest, long totalBytes, long downloadedBytes, int progress) {
                   }
               });
       manager.add(downloadRequest);
   }
@jhysum
Copy link

jhysum commented Oct 2, 2019

I get this as well
`private void transferData(DownloadRequest request, InputStream in, RandomAccessFile out) {
final byte data[] = new byte[BUFFER_SIZE];
long mCurrentBytes = mDownloadedCacheSize;
request.setDownloadState(DownloadManager.STATUS_RUNNING);
Timber.v("Content Length: " + mContentLength + " for Download Id " + request.getDownloadId());
for (; ; ) {
if (request.isCancelled()) {
Timber.v(STOPPING_THE_DOWNLOAD_AS_DOWNLOAD_REQUEST_IS_CANCELLED, request.getDownloadId());
request.finish();
updateDownloadFailed(request, DownloadManager.ERROR_DOWNLOAD_CANCELLED, DOWNLOAD_CANCELLED);
return;
}
int bytesRead = readFromResponse(request, data, in);

        if (mContentLength != -1 && mContentLength > 0) {
            int progress = (int) ((mCurrentBytes * 100) / mContentLength);
            updateDownloadProgress(request, progress, mCurrentBytes);
        }

        if (bytesRead == -1) { // success, end of stream already reached
            updateDownloadComplete(request);
            return;
        } else if (bytesRead == Integer.MIN_VALUE) {
            return;
        }

        if (writeDataToDestination(request, data, bytesRead, out)) {
            mCurrentBytes += bytesRead;
        } else {
            request.finish();
            updateDownloadFailed(request, DownloadManager.ERROR_FILE_ERROR, "Failed writing file");
            return;
        }
    }
}`

I think in here we get to bytesRead == -1 somehow. I haven't started debugging this yet but I get this sometimes.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants