Pasting some image from Chrome won't import the image to the media database

Steps to reproduce:

  1. Go to this URL
    https://www.researchgate.net/publication/372533503/figure/fig1/AS:11431281270911835@1723283890520/Carotid-sinus-and-carotid-body-The-carotid-sinus-nerve-a-branch-of-the-glossopharyngeal.jpg

  2. Copy the image

  3. Paste that to Anki.

  4. Notice the 403 error and the resulting image. src attribute pointing to remote URL, rather than downloading the media.

Gonna make a PR for this. Leaving this post as a reminder.

See Revert "Prefer image pastes over HTML in the editor (#2856)" Ā· ankitects/anki@174a2e7 Ā· GitHub

Are you on a vpn?

1 Like

Oh, this had already been discussed.

No, I’m not behind any VPN. It seems like some sites don’t like Anki’s user agent or so.

1 Like

This thread is also related:

1 Like

Posted a quick PR draft. This pr conserves filename and alt when the download succeeds.

1 Like

For record, I think anki should download the original image whenever possible instead of using the clipboard data, as it would allow…

  • Animated GIF
  • Image with transparency (may not be respected on the clipboard)
  • Lossless embedding of non-jpg images.

https://ankiweb.net/shared/info/934503660

Created an addon for the issue. Likely the PR won’t be merged cause Anki’s undergoing some serious redesign on the card editor.

1 Like

You might want to insert the image as a reference to keep an image up-to-date. But this shouldn’t be default behavior, so I agree with you. I’m not well into this particular issue, but perhaps the insert-as-reference is already a fallback when image download isn’t working?
After all, it’s strange that an error 403 is shown before then displaying the correct image. Maybe a different user agent is used when trying to download the image versus when displaying it for the user? On other images, my Anki just runs into unhandled exceptions.

Maybe a different user agent is used when trying to download the image versus when displaying it for the user?

I think so. Anki uses Mozilla/5.0 (compatible; Anki) as a user agent when retrieving a URL, without any referer or so.