Skip to content

Feature: reuse the earlier upload of an unchanged local image #97

Open

Description

@MattFisher

Use case

I keep a post as a Markdown file with local image paths and push it to the same draft many times while editing (Api.update_draft_from_markdown or Post.from_markdown(..., api=api) followed by put_draft). The Markdown file is the source of truth, so the image paths stay local and never become Substack URLs.

Every push uploads every local image again through Api.get_image(), even when the file has not changed. For a post with four screenshots that is four uploads per push, and as far as I can tell each upload is stored as a new image with its own URL. drafts update --dry-run uploads them too.

(The export, edit, update round trip does not have this problem, because exported Markdown already contains Substack URLs.)

Proposed API or CLI

Something that lets the library reuse the earlier upload when the file's bytes are the same. I can see a few shapes, and I'd like to know which fits the project before writing anything:

# 1. Opt-in record file kept by the library
api = Api(cookies_path="cookies.json", image_upload_record=".substack-uploads.json")

# 2. A hook, with storage left to the caller
post.from_markdown(markdown, api=api, upload_image=my_cached_upload)

# 3. CLI flag on top of either
#    substack drafts update 12345 post.md --yes --reuse-uploads

Questions I'd like your view on:

  • Should the library own a state file at all, or only offer a hook?
  • If it owns one, where should it live by default (next to the Markdown file, a user cache folder, or only where the caller says)?
  • Should it stay off by default? I assume yes under the 1.x compatibility policy.

Alternatives

I currently wrap api.get_image in my own script:

  • The key is the SHA-256 of the file's bytes, recorded per publication URL, and the value is the whole upload response (so the URL, dimensions, byte size and content type are all reused).
  • Before reusing an entry, the script sends a HEAD request to the stored URL and uploads again unless it returns 200. This covers images that have since been removed from Substack.
  • An unreadable or malformed record file is treated as empty.

This works, and keying on content means a renamed or reverted file is still recognised. I'm happy to turn it into a PR in whichever shape you prefer.

Posted by Claude Code on Matt's behalf.

Activity

  1. ma2za commented on Dec 3, 2026

    @ma2za
    Owner

    Thanks, Matt. I’d be happy to review a PR for an opt-in upload hook. Could you wire it into Api.update_draft_from_markdown() as well as Post.from_markdown() so it covers the repeated draft update workflow you described?

    I’d leave cache storage and URL validation to the caller for now. Your approach of keying by publication and file contents makes sense. The hook should return the full upload response so reused images keep their dimensions, byte size, and content type. We can revisit a built-in cache or CLI flag once we’ve used the hook.

    I also confirmed that drafts update --dry-run can upload images. I’d track that as a separate bug because dry runs should avoid uploads whether or not caching is enabled.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions