Serviceworker download files

Serviceworker download files

serviceworker download files

Now you say that we can achieve the same by just using the fetch event of the service worker. Yes, we can download some file and put it into. The service worker is a generic entry point for event-driven background processing in the Web HTML documents are loaded over HTTP and traditionally fetch all of their The postMessage(message, transfer) method must run these steps. The endpoint to the service-worker.js file is quite important. for instance, one of the resources failed to be downloaded, the service worker won't be installed.

Serviceworker download files - can not

Corrupt file download in Chrome with service worker

We have an Angular Web App with service workers for some basic caching. The backend is a Spring Boot Java application that provides various services via REST interfaces. Amongst others, we have GET requests to download files.

Everything worked fine for months, but since Chrome v71, we have the following problem: if we download a file via the REST service, the download itself completes, but if we try to open it (e.g. a PDF), this does not work since the file is corrupt. The reason is that the file is not downloaded completely. For example, we tried with a PDF that has a size of 539kb. During several downloads, we got always files of different sizes, 506kb, 504kb, 518kb, ... Sometimes we also get the complete file and then it can be opened without any problems. This happens only in Chrome (we cannot reproduce in any other Browser, neither, FF, nor Safari, nor IE). After hours of debugging, we found that this is somehow related to service workers. If we unregister the service worker and trigger the download afterwards, we always get a complete file.

I checked all changes of Chrome v71 and found this one concerning Background Fetch API -> https://www.chromestatus.com/feature/5712608971718656.

The creation of the ResponseEntity for the GET service in the backend (we already checked that the Content-Length attribute is always set correctly):

Our service worker configuration (basically, we cache some assets and exclude every /api/** URL (the file download URL fulfills this pattern):

We download the file by opening a new browser window with the according URL for the GET request:

I will also open a ticket for Chrome so that they can check if this is something that needs to be fixed in the service worker implementation. Anyways, if there is someone who came across a similar issue or who has an idea how this could be fixed (without disabling service workers completely, what is actually our current fix), please let me know. Thanks!

UPDATE: The according Chromium issue: https://bugs.chromium.org/p/chromium/issues/detail?id=917958&q=corrupt&colspec=ID%20Pri%20M%20Stars%20ReleaseBlock%20Component%20Status%20Owner%20Summary%20OS%20Modified

Источник: [https://torrent-igruha.org/3551-portal.html]

Serviceworker download files - remarkable

serviceworker download files

Serviceworker download files

1 thoughts to “Serviceworker download files”

Leave a Reply

Your email address will not be published. Required fields are marked *