Giter Site home page Giter Site logo

Comments (8)

tonyofrancis avatar tonyofrancis commented on May 14, 2024 2

Seems like there is a bug. I am looking into it

from fetch.

tonyofrancis avatar tonyofrancis commented on May 14, 2024 2

@RealAction Can you try this work around and let me know if it works for you? I am still looking into this issue.

Work Around:

          DownloadInfo toDownload= mListDownloadInfo.get(holder.getAdapterPosition());
                final Request request = new Request(toDownload.getUrl()
                        , Environment.getExternalStoragePublicDirectory(Environment.DIRECTORY_DOWNLOADS).getPath()
                        ,toDownload.getFileName());

                final RequestInfo requestInfo = mFetchDownloader.get(request);

                if(requestInfo != null && requestInfo.getError() == Fetch.ERROR_FILE_NOT_FOUND) {

                    Log.e("aaaa", "aaaa:"+requestInfo.getStatus());
                    Log.e("aaaa", "aaaa:"+requestInfo.getError());

                    mFetchDownloader.addFetchListener(new FetchListener() {
                        @Override
                        public void onUpdate(long id, int status, int progress, long downloadedBytes, long fileSize, int error) {

                            if(id == requestInfo.getId() && status == Fetch.STATUS_REMOVED) {

                                mFetchDownloader.enqueue(request);
                                mFetchDownloader.removeFetchListener(this);
                            }
                        }
                    });

                    mFetchDownloader.remove(requestInfo.getId());
                }else {
                    toDownload.setDownloadId(mFetchDownloader.enqueue(request));
                }

from fetch.

sriram-kakarala avatar sriram-kakarala commented on May 14, 2024 2

@RealAction - Not sure if I am understanding correctly, but if you want to re-download the same file at the same Location, just do a fetch.retry(old_download_id). I am doing the same and it seems to work. Although having the file removed from Fetch DB easily is desirable, this workaround seems to work for me in both the cases.

from fetch.

DevOfLife avatar DevOfLife commented on May 14, 2024 1

the code you post above fix half of issues, that make me confuse. Let me explain in 2 script:
NOTICE:

  • in both 2 script Fetch will release then re-instance before user download
  • i put 2 line "aaaa" log outsize of if block

Script 1 (success):

  • Download the file
  • User manually kill app completely (by click phone's menu button then slide to kill app)
  • Delete the downloaded file
  • User open app again then download
  • Result: work perfect (download again success)

Script 2 (not success):

  • Download the file
  • User kill app (by click back button until app close)
  • Delete the downloaded file
  • User open app again then download
  • Result:
05-23 21:52:44.679 14855-14855/com.devoflife.app.testdownload E/aaaa: aaaa:903 //status
05-23 21:52:44.679 14855-14855/com.devoflife.app.testdownload E/aaaa: aaaa:-1 //error
05-23 21:52:44.680 14855-14855/com.devoflife.app.testdownload W/System.err: com.tonyodev.fetch.exception.EnqueueException: DatabaseHelper already containsFilePath a request with the filePath:/storage/emulated/0/Download/pic_mountain.jpg

from fetch.

tonyofrancis avatar tonyofrancis commented on May 14, 2024

@RealAction The FetchService automatically removes the entry for a request if the file is moved or deleted. Can you provide me a sample app or log?

from fetch.

tonyofrancis avatar tonyofrancis commented on May 14, 2024

@RealAction disregard my previous answer. The following is how Fetch handles downloaded files that have been removed.

Every time the FetchService starts, its verifies the database by checking that the downloaded files still exist. If a file was deleted or cannot be accessed, the service sets the request status to Fetch.STATUS_ERROR with an error value of Fetch.ERROR_FILE_NOT_FOUND.

What you can do is query fetch for the request and check its status. If the status is invalid, remove the request and enqueue again. Example:

        final Request request = new Request("url","dirPath","fileName");
        final RequestInfo requestInfo = fetch.get(request);

        if(requestInfo != null && requestInfo.getStatus() == Fetch.STATUS_ERROR
                && requestInfo.getError() == Fetch.ERROR_FILE_NOT_FOUND) {

            //Listen for when the request has be removed
            fetch.addFetchListener(new FetchListener() {
                @Override
                public void onUpdate(long id, int status, int progress, long downloadedBytes, long fileSize, int error) {

                    if(id == requestInfo.getId() && status == Fetch.STATUS_REMOVED) {
                        //Enqueue request
                        long downloadId = fetch.enqueue(request);
                        
                        //Save downloadId....
                        
                        fetch.removeFetchListener(this);
                    }
                }
            });

            fetch.remove(requestInfo.getId());
        }else {
           long downloadId =  fetch.enqueue(request); //Save downloadId....
        }

Let me know if this works how you except.

from fetch.

RealAction avatar RealAction commented on May 14, 2024

@tonyofrancis
i made simple example so you can see issue: https://github.com/DevOfLife/TestDownload5
step:

  • click into folder icon to download the sample image (located on Downloads folder of sd card)
  • close the app
  • Delete the downloaded image
  • then re-open the app
  • click into folder icon again to download

result log:
05-19 22:28:34.359 8084-8084/com.devoflife.app.testdownload E/aaaa: aaaa:904 //status
05-19 22:28:34.359 8084-8084/com.devoflife.app.testdownload E/aaaa: aaaa:-111 //error
05-19 22:28:34.363 8084-8084/com.devoflife.app.testdownload W/System.err: com.tonyodev.fetch.exception.EnqueueException: DatabaseHelper already containsFilePath a request with the filePath:/storage/emulated/0/Download/pic_mountain.jpg
05-19 22:28:34.363 8084-8084/com.devoflife.app.testdownload W/System.err: at com.tonyodev.fetch.DatabaseHelper.getInsertStatement(DatabaseHelper.java:147)
05-19 22:28:34.363 8084-8084/com.devoflife.app.testdownload W/System.err: at com.tonyodev.fetch.DatabaseHelper.insert(DatabaseHelper.java:166)
05-19 22:28:34.363 8084-8084/com.devoflife.app.testdownload W/System.err: at com.tonyodev.fetch.Fetch.enqueue(Fetch.java:292)
05-19 22:28:34.363 8084-8084/com.devoflife.app.testdownload W/System.err: at com.devoflife.app.testdownload.PresentationAdapter.ListDownloadAdapter$3.onClick(ListDownloadAdapter.java:106)
05-19 22:28:34.363 8084-8084/com.devoflife.app.testdownload W/System.err: at android.view.View.performClick(View.java:5610)
05-19 22:28:34.363 8084-8084/com.devoflife.app.testdownload W/System.err: at android.view.View$PerformClick.run(View.java:22265)
05-19 22:28:34.363 8084-8084/com.devoflife.app.testdownload W/System.err: at android.os.Handler.handleCallback(Handler.java:751)
05-19 22:28:34.363 8084-8084/com.devoflife.app.testdownload W/System.err: at android.os.Handler.dispatchMessage(Handler.java:95)
05-19 22:28:34.363 8084-8084/com.devoflife.app.testdownload W/System.err: at android.os.Looper.loop(Looper.java:154)
05-19 22:28:34.363 8084-8084/com.devoflife.app.testdownload W/System.err: at android.app.ActivityThread.main(ActivityThread.java:6077)
05-19 22:28:34.363 8084-8084/com.devoflife.app.testdownload W/System.err: at java.lang.reflect.Method.invoke(Native Method)
05-19 22:28:34.363 8084-8084/com.devoflife.app.testdownload W/System.err: at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:865)
05-19 22:28:34.363 8084-8084/com.devoflife.app.testdownload W/System.err: at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:755)

from fetch.

ebkhmobile avatar ebkhmobile commented on May 14, 2024

HI
if I want to update an downloaded file, Fetch don't allow me! and return -1 as download id.
I think that u must add a method to remove download data from fetch database without deleting the file.
if i use fetch.RemoveAll() it will work good but this method will delete my old file. so if my updat crash, then i have no file!

from fetch.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.