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

Failure to open local file in windows platform #9020

Closed
juncaixinchi opened this issue Oct 11, 2017 · 8 comments
Closed

Failure to open local file in windows platform #9020

juncaixinchi opened this issue Oct 11, 2017 · 8 comments
Labels

Comments

@juncaixinchi
Copy link
Contributor

Configuration:

  • Web browser and its version:
    Electron 1.7.8 ( use webpack and set target: 'electron-renderer')
  • Operating system and its version:
    Windows 10
  • PDF.js version:
    pdfjs-dist: 1.9.640
  • Is an extension:
    no

Steps to reproduce the problem:

  1. try to open C:/User/1234/Desktop/a.pdf
  2. window.location transform it to file:///C:/User/1234/Desktop/a.pdf
  3. PDFNodeStreamFsFullReader get /C:/User/1234/Desktop/a.pdf
  4. ENOENT: no such file or directory, lstat C:\C:\User\1234\Desktop\a.pdf

What went wrong?

the pr #8928 is not working

path before decodeURI: /C:/User/1234/Desktop/a.pdf. Howerver, after decodeURI, path is still the same.

see also
#8946

@pcad
Copy link

pcad commented Oct 16, 2017

@juncaixinchi - We had a similar issue. PDFJS switched in the 1.9 release to the fetch api. Fetch in Electron doesn't work the same way as XHR wrt the file:// protocol.

electron/electron#9474 (comment)

@juncaixinchi
Copy link
Contributor Author

@pcad if you use webpack, you can set target: 'electron-renderer' or target: 'electron in webpack.config.js, then PDFJS will using Node Stream to load local file rather than fetch api.

However, due to the bug I refered in this issue, it's only working in Linux or Mac platform, failed in windows.
About fetch, file:// protocol was refused to add to fetch api. ╮( ̄ .  ̄)╭

JakeChampion/fetch#92 (comment)

@matteodem
Copy link

So what's the solution to this problem?

@juncaixinchi
Copy link
Contributor Author

@matteodem A PR(#9323) has been added to solve this problem, you can try the latest release, it should be OK.

@matteodem
Copy link

@juncaixinchi I get following error:

fetch_stream.js:96 Fetch API cannot load file:///C:/Users/demichma/Downloads/ZH_BD_CD_07773.pdf. URL scheme must be "http" or "https" for CORS request.

see http://jsfiddle.net/9engc9mw/2601/

Does the build version have to be updated too?

@juncaixinchi
Copy link
Contributor Author

@matteodem

That's becasue the fetch api does not support file protocol (JakeChampion/fetch#92 (comment)).

You should use http protocol: http://jsfiddle.net/9engc9mw/2611/.

If you are electron and webpack user, see #9020 (comment)

@matteodem
Copy link

@juncaixinchi ...so this means this is not possible? as in the original issue is unresolved / unresolvable?

@juncaixinchi
Copy link
Contributor Author

@matteodem It's not possible to use the fetch api to load local files via file protocol. However, the pdf.js supports reading local files if you are in NodeJS environment.

movsb pushed a commit to movsb/pdf.js that referenced this issue Jul 14, 2018
Get correct path in node_stream on windows platform( issue mozilla#9020)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

No branches or pull requests

4 participants