-
Notifications
You must be signed in to change notification settings - Fork 2.8k
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
Add support for file protocol (File URI Schema) #92
Conversation
+1 for this pull. |
+1 for this pull. |
Neither Chrome's nor Firefox's native implementation supports fetching local files. I think it was intentionally. The fetch spec doesn't explicitly forbid the I'm sorry, but I don't think fetch is meant for local files right now. You're better off using XHR. |
Just a note to point out that this is quite annoying when making hybrid mobile apps (e.g. with Cordova) which regularly need access to local files. |
+1 for Cordova Apps |
function fetchLocal(url) {
return new Promise(function(resolve, reject) {
var xhr = new XMLHttpRequest
xhr.onload = function() {
resolve(new Response(xhr.responseText, {status: xhr.status}))
}
xhr.onerror = function() {
reject(new TypeError('Local request failed'))
}
xhr.open('GET', url)
xhr.send(null)
})
} |
I think this was mentioned elsewhere, but as of today Firefox supports fetch for Chrome/Chromium still does not, but I have submitted a bug report because XHR does support it, with the appropriate command-line switch. |
To summarize, mislav's suggestion only works in Chrome with |
inspired by @mislav
In case you are using something like angular and then using cordova to transform it into an application you can put the below at the top of the pollyfills.ts(find in the src folder) file
|
This commit would work while fetching a
file:///
protocol resource, mentioned in issue #91