-
Notifications
You must be signed in to change notification settings - Fork 87
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
Can't load file #29
Comments
This issue is fixed on the pull request #30 To fix this, go to: /svgexport/render.js line 43: Change that to: However, it seems Travis CI is failing. All I did was add a few characters into the code yet the error its throwing is no environment variables check and etc. |
Can you please share the exact code or command you are using? Meanwhile I t don't think this is good solution, because for example it does not work with relative locations or any protocol other than |
The exact command I used was:
My OS is Windows 7. Further debug was that the protocol was unknown for "c" or "d" (depending on which drive the file is from) for abc.svg |
Can I ask where the abc.svg file is located? Probably you can just use |
The error shown:
I have verified twice, thrice, 4 times that the path is correct. The error returned was:
|
Have you tried backslash |
Seriously?
Clearly I didn't state the path. Clearly the path was inferred by your code (_dirname). It's not my choice it's a forward or backward slash. Furthermore, windows by default is that format. |
The reason I chose to put 'file:///' is because that's the only protocol that is supporting opening of files from the file system by a browser. (Try opening a HTML, svg or any file in your browser. Then see the url. It'll be prefix with that 'file:///') Your concern on whether it's a relative path or not is not really valid as I placed that code at the final section (load said file in phantomjs). All relative paths have their full paths inferred before that. The proof is that I pass in a relative path of my svg and it can still work. |
As far as I know Windows uses backslash not forward slash, that is I'm not sure why your path is not being resolved correctly, but I think it's better to fix it first. |
Ouch. My bad. Sorry for that. My path is in the forward slash. And I dare say it has nothing to do with the path. If the path is wrong it will fail much earlier |
I see, so is there still any issue? |
Like i have been saying from the start, the path is NOT the issue here... The issue is with the latest upgrade of phantomjs that is reading 'c' (if the file path starts with (C:)) is an invalid protocol. The path is fine. It just fails when it tries to load the path into phantomjs. |
On OSX 10.11.4
|
Same here. If I try to execute svgexport, the path is resolved perfectly fine, but it fails to open with said error:
OS is Windows 10; svgexport executed in PowerShell. |
@Tiliavir follow my fix as I have shown above for now as the PR is not approved. |
Thanks worked perfectly - hope to see it in the repo soon... |
I was having the same problem and I have a potential fix based on the one suggested by @tlkiong but should also satisfy the concerns of @shakiba I found that neither relative nor absolute paths would work. I modifed page.onResourceError = function(resourceError) {
console.log('Unable to load resource (URL:' + resourceError.url + ')');
console.log('Error code: ' + resourceError.errorCode);
console.log('Description: ' + resourceError.errorString);
}; This error information indicated that @tlkiong is on the right track as PhantomJS is confused by the URI that is being given to its Out of interest I checked using a HTTP URI and got the same error. Based on this information I made the following change to input[0] = path.resolve(cwd, input[0]); Modified Code var url = require('url');
var parsedUrl = url.parse(input[0]);
if (parsedUrl.protocol !== 'http:') {
input[0] = 'file:///' + path.resolve(cwd, input[0]);
} This fix should allow the program to work with relative and absolute file paths and also open HTTP URIs. |
That was what I was thinking initially. However, at the beginning of the code where the call is made to the relative or absolute path, it is only fetching from the filesystem. This means it isn't a http URI but only can be a fs path. That's the reason for not checking whether it's a http or not as it is unnecessary. That's my opinion though |
The reason my PR is doing it at the final stage is to give it the code a bit of flexibility in terms of being able to do anything with the file (since we need the file path) before loading it to phantomjs. If we were to do it at index.js at the start and if in the future there would be a need for new features to enable modification of file contents, it will be a problem. |
I see, actually I expect it to be fixed by phantomjs in future. As a short-term workaround, I think fixing it at the same place that file path is resolved would be better. |
I don't think there will be a "fix" by phantomjs as this is the correct way for phantomjs to handle it It was a deliberate improvement on their part to add this in |
I only suggested making a change in |
Although, something like this would probably work in var link = document.createElement('a');
link.href = svgfile;
if (link.protocol !== 'http:') {
svgfile = 'file:///' + svgfile;
} |
I added following temporary fix, can you please check it: if (/^[a-z]\:\\/.test(input[0])) {
input[0] = 'file:///' + input[0];
} |
I published a new version with the fix, please let me know if the issue is not resolved. Thanks everyone for reporting and other helps! |
Receive the following error:
The text was updated successfully, but these errors were encountered: