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

Unable to upload local image in Windows #61

Open
lukefan6 opened this issue Sep 23, 2019 · 5 comments
Open

Unable to upload local image in Windows #61

lukefan6 opened this issue Sep 23, 2019 · 5 comments
Assignees
Labels

Comments

@lukefan6
Copy link

Let's say I have a local image file called my-code-doesnt-work.jpg alongside my markdown slide and I simply add it to the slide like this:

---
# Title

![](my-code-doesnt-work.jpg)
---

When I executed the converter, error message popped out as follows:

Unable to generate slides: { [Error: ENOENT: no such file or directory, open 'c:\c:\git\others\not-so-personal-notes\Stretch\slides\my-code-doesnt-work.jpg']

After some hacking I was able to pinpoint the cause to this line of code:
https://github.com/gsuitedevs/md2googleslides/blob/master/src/images/probe.ts#L62

I used console.log to print the parsedUrl.pathname and the result was

/c:/git/others/not-so-personal-notes/Stretch/slides/my-code-doesnt-work.jpg

Then it was passed to fs.createReadStream(path); and that's where the error came from.

I can hack it to resolve my issue by using fs.createReadStream(path.substring(1)); but obviously it's not an ideal solution and I have no idea whether it will affect macos / linux or not.

Any ideas?

@py9mrg
Copy link

py9mrg commented Aug 30, 2023

Hello @lukefan6 ,

Would you please be able to walk me through your fix because I have the same issue and unable to fix it?

I know almost zero about TS and JS. I've tried making the modification you mention in my installed version of md2googleslides (ie not the GitHub repos I cloned), in the location md2gslides\lib\images\probe.js.map, but this doesn't fix it (it's the only code matching what you mention above). Presumably it's to do with the compilation from TS to JS but, like I said, that's way beyond me.

Note, I'm using a forked version fly @wescpy that has updated various things including the OAuth.

Is there a way I can fix it in my installed version (or can you guide me how to do a PR for wescpy bearing in mind my non-existent TS and JS skillset!).

Thanks.

@lukefan6
Copy link
Author

@py9mrg I haven't been following this for quite a long time.

As you can see, my post was in 2019, that's almost 4 years ago, and I believe the source code architecture has changed a lot since then.

That said, what I am able to help you now is try to locate the code, so I used the GitHub history feature to find out what the code looked like 4 years ago, and here it is:

https://github.com/googleworkspace/md2googleslides/blob/828a918dbbae948002086668f18de96f6964d079/src/images/probe.ts#L62C49-L62C49

I guess now you can go checkout the latest version of the file src/images/probe.ts and locate to async function probeImage then find the similar line on 63:

    const size = await probeFile(parsedUrl.pathname);

Then, you should be able to modify it and try the hack that I was able to do 4 years ago.

As for compiling and running the modified code, I'm afraid I have to tell you that I don't remember how I did it 4 years ago.

My recommendation is that you ask some other contributors to this project as they are the TS and JS experts and are supposed to answer the how-to-get-it-running questions.

That's all I have now, good luck to you, cheers!

@py9mrg
Copy link

py9mrg commented Aug 31, 2023

Thanks a lot. The project has been largely dormant for those 4 years, apart from some extremely helpful authentication work by @wescpy, so it might be the case that your fix works as is! I'll give it a go, thanks a lot for the advice.

@py9mrg
Copy link

py9mrg commented Sep 19, 2023

Sorry for the delay, it's taken me some time to have a chance to test this. @lukefan6 you are a hero, I had to make a couple of modifications but using your guidance I could work it out and finally have it working after years of trying (admittedly very sporadically)! Now both local images and equations (which use local images) work fine.

tl;dr I needed to add .substring(1) into said function in two files (probe.js and upload.js) because the local images use fileio as an intermediary these days.

Edit [
i.e. in both files change something like:
const stream = _fs.default.createReadStream(filePath); (or just path)

into something like this:
const stream = _fs.default.createReadStream(filePath.substring(1));
]

@wescpy hope everything is ok with you - I can do a pull request on this but I am reluctant to initiate it because this might just be a Windows thing so I think it's likely it could break it for everyone else. I will try to get a chance to test it on Linux / (very old) macOS when I have the chance.

@lukefan6
Copy link
Author

@py9mrg Congratulations on your success, I'm so happy for you!

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

3 participants