Kareadita/Kavita · warning · KavitaException
Cannot copy external images
Error message
Cannot copy external images
What it means
Thrown by BookService.CopyImageToTempFromBook (line 1279) when the resolved image source key starts with 'http', i.e. the image is an external URL rather than an epub-internal resource. Kavita cannot (and will not) fetch remote images during image copy.
Source
Thrown at Kavita.Services/BookService.cs:1279
var targetImage = images[bookmarkDto.ImageOffset];
// Get the image source attribute
var srcAttributeName = GetImageSrcAttributeName(targetImage);
if (string.IsNullOrEmpty(srcAttributeName))
{
throw new KavitaException("Image element does not have a valid source attribute");
}
var imageSource = targetImage.Attributes[srcAttributeName].Value;
// Clean and get the correct key for the image
var imageKey = CleanContentKeys(GetKeyForImage(book, imageSource));
// Check if it's an external URL
if (imageKey.StartsWith("http"))
{
throw new KavitaException("Cannot copy external images");
}
// Get the image file from the epub
if (!book.Content.Images.TryGetLocalFileRefByKey(imageKey, out var imageFile))
{
throw new KavitaException($"Image file not found in epub: {imageKey}");
}
// Read the image content
var imageContent = await imageFile.ReadContentAsBytesAsync();
// Determine file extension from the image key or content type
var extension = Path.GetExtension(imageKey);
if (string.IsNullOrEmpty(extension))
{
// Fallback to determining extension from content type
extension = imageFile.ContentType switchView on GitHub (pinned to 9c3e540000)
Solutions
- Re-package the epub to embed the image as an internal resource instead of an external URL.
- On the client, disable copy-image for pages known to reference remote images.
Example fix
// before
if (imageKey.StartsWith("http"))
throw new KavitaException("Cannot copy external images");
// caller — pre-check the image source scheme
if (Uri.TryCreate(imageSrc, UriKind.Absolute, out var u) && u.Scheme.StartsWith("http"))
return BadRequest("External images cannot be copied"); Defensive patterns
Strategy: validation
Validate before calling
// Reject external-image pages before requesting copy
if (Uri.TryCreate(src, UriKind.Absolute, out var u) && (u.Scheme == "http" || u.Scheme == "https"))
return BadRequest("External images cannot be copied"); Prevention
- Re-package epubs to embed images internally rather than hot-linking URLs.
- On the client, detect remote src and disable copy-image.
When it happens
Trigger: Bookmark/copy-image request on a page whose <img src> is an absolute http(s) URL to a remote server rather than a path inside the epub.
Common situations: Epubs that hot-link cover art or illustrations from a publisher CDN; DRM/preview epubs with remote-only images.
Related errors
- No images found on the specified page
- Image index {bookmarkDto.ImageOffset} is out of range. Page
- Image element does not have a valid source attribute
- Page {bookmarkDto.Page} not found in epub
- Image file not found in epub: {imageKey}
AI-assisted analysis of Kareadita/Kavita@9c3e540000 (2026-08-13).
Data as JSON: /api/errors/3e666c85bf7dc6bd.
Report an issue: GitHub.