renmu123 / obsidian-image-auto-upload-plugin

auto upload image with picgo
MIT License
350 stars 38 forks source link

Picgo-Core Error on Mac #20

Open zcysxy opened 2 years ago

zcysxy commented 2 years ago

Support for Picgo-core works fine on Windows, but has an error on Mac (M1 chip, MacOS 12.2.1).

I have the same .picgo/config.json on both systems, and Picgo-core CLI works fine on both systems (see the screenshot below).

Screen Shot 2022-03-02 at 20 51 17

However, when I paste an image in Obsidian, it gives me the error: ⚠️upload failed, check dev console. And in the console the error is

image

Please let me know if you need more information.

OuttaSpaceTime commented 2 years ago

Hey I am having the same error with this plugin and pic core but on ubuntu.

I got it working with typora and command line.

zcysxy commented 2 years ago

I found a workaround if you want to upload the image in clipboard, using another plugin Shell Commands. Just add the following command in the Shell Commands settings

echo "![]($(picgo upload | tail -n +6))"

But this command will not work if picgo and node are not in the Shell Commands path. I use nvm to manage node, so I need to add the execution of the nvm script to the command:

\. "/opt/homebrew/opt/nvm/nvm.sh" && echo "![]($(picgo upload | tail -n +6))"

Also, for me the image link is returned at the 6th line, so I use tail -n +6 to remove the first 5 lines. If you use different picgo settings, this might be different.

Then in Shell Commands settings, set an alias for the command and set output channel as Current file: caret position.

Now everything should work. Notice that this workaround will not automatically upload the image for you, you may want to combine a hotkey to the command. For example, I use cmd + U.

zcysxy commented 2 years ago

I figured out the problem: on macOS and Linux, JavaScript child process doesn't read the PATH properly. As in the doc:

The command lookup is performed using the options.env.PATH environment variable if env is in the options object. Otherwise, process.env.PATH is used. If options.env is set without PATH, lookup on Unix is performed on a default search path search of /usr/bin:/bin (see your operating system's manual for execvpe/execvp), on Windows the current processes environment variable PATH is used.

So on Windows, all paths are stored in the PATH environment variable, hence will be read by the child process; but on macOS and Linux, paths are extended in the .zshrc/.bashrc files, which are not read by the child process.

Therefore for me, the problem is that the path to node is not looked up by the child process. So for me the solution is, in plugin settings, set PicGo-Core path as

\. "/opt/homebrew/opt/nvm/nvm.sh" && picgo

Then everything works fine.

AGou-ops commented 2 years ago

I figured out the problem: on macOS and Linux, JavaScript child process doesn't read the PATH properly. As in the doc:

The command lookup is performed using the options.env.PATH environment variable if env is in the options object. Otherwise, process.env.PATH is used. If options.env is set without PATH, lookup on Unix is performed on a default search path search of /usr/bin:/bin (see your operating system's manual for execvpe/execvp), on Windows the current processes environment variable PATH is used.

So on Windows, all paths are stored in the PATH environment variable, hence will be read by the child process; but on macOS and Linux, paths are extended in the .zshrc/.bashrc files, which are not read by the child process.

Therefore for me, the problem is that the path to node is not looked up by the child process. So for me the solution is, in plugin settings, set PicGo-Core path as

\. "/opt/homebrew/opt/nvm/nvm.sh" && picgo

Then everything works fine.

不管用呀,设置了之后还是那个报错.

image

绝对路径也不管用.

AGou-ops commented 2 years ago

没事了,现在好了,加上PATH就可以了,是我npm路径找不到导致的(注意使用全路径,不要用~,不然也不行.)

\. "/Users/agou-ops/.nvm/nvm.sh" && export PATH="/opt/homebrew/bin:$PATH" && /opt/homebrew/bin/npx picgo u
cs-mshah commented 2 years ago

I am unable to use this. I just put /home/manan/.config/Typora/picgo/linux/picgo in the PicGo-Core path, but it gives the same error. I am not using nvm. How should I fix this? other things like
/home/manan/.config/Typora/picgo/linux/picgo upload and \. /home/manan/.config/Typora/picgo/linux/picgo also do not work.