Upload Dev.to Images from Terminal with devpub CLI
Job to be done: Upload images to Dev.to from the terminal using a custom CLI tool
π³π¬ Ways to use this in Nigeria
Ideas to get you started, adapt to your situation.
- Student
As a computer science student, use `devpub` to upload project screenshots and code diagrams to your Dev.to articles, documenting your final year project or coding assignments for your portfolio.
- Entrepreneur
As a tech startup founder, use `devpub` to efficiently upload product screenshots and architectural diagrams to your Dev.to blog posts, sharing technical updates and attracting early adopters.
- 9-5 employee
As a software engineer, use `devpub` to quickly upload code snippets and UI mockups to your company's internal Dev.to knowledge base articles, streamlining technical documentation for your team.
What youβll get
You will be able to upload images directly to your Dev.to posts from your computerβs command line interface (CLI). This saves you the time of manually uploading images through the Dev.to website. This approach works because the devpub tool cleverly mimics the browserβs image upload process, even though the official Forem API doesnβt have a direct image upload feature.
Tools you need
- devpub CLI (free): A command-line tool that helps you manage your Dev.to posts, including uploading images.
- Forem API (paid): The underlying API that Dev.to uses. While the API itself doesnβt have a direct image upload endpoint, the devpub tool uses it indirectly by interacting with Dev.toβs web interface.
Steps
-
Install the devpub CLI: If you donβt have it already, youβll need to install the devpub tool. The author used version 0.3.0.
pip install devpub == 0.3.0You should see output indicating that the package has been successfully installed.
-
Get your Dev.to session cookie and CSRF token: The devpub tool needs these to authenticate your uploads, as the Forem API doesnβt directly support image uploads. You can find these by inspecting your browserβs cookies and network requests when you are logged into Dev.to.
- Open Dev.to in your browser and log in.
- Open your browserβs developer tools (usually by pressing F12).
- Go to the βApplicationβ or βStorageβ tab and find the cookies for
dev.to. Look for_Devto_Forem_Session. - Go to the βNetworkβ tab, and try to upload an image manually through the Dev.to editor. Look for a request to
/image_uploads. Inspect the request headers for theX-CSRF-Token. - Save these values. The author stores them in a
.envfile in the.devpub/directory, but this file is ignored by git.
You will need to have these two pieces of information to proceed.
-
Configure devpub with your credentials: The author mentions that these credentials are stored in
.devpub/.env. You will need to create this file and add your session cookie and CSRF token.# Create the directory if it doesn't exist mkdir -p .devpubCreate a file named
.devpub/.envand add your credentials. The exact format is shown in the original source, but it looks like this:DEVPUB_SESSION_COOKIE=_Devto_Forem_Session = YOUR_SESSION_COOKIE_VALUE DEVPUB_CSRF_TOKEN=YOUR_CSRF_TOKEN_VALUEReplace
YOUR_SESSION_COOKIE_VALUEandYOUR_CSRF_TOKEN_VALUEwith the actual values you found in step 2. -
Upload an image: Use the
devpub uploadcommand followed by the name of your image file.devpub upload cover.pngYou should see output similar to this, showing the uploaded file and its URL:
Uploaded: cover.png Uploaded Images ββββββββββββββββ³βββββββββββββββββββββββββββββββββββββββββββ β File β URL β β‘ββββββββββββββββββββββββββββββββββββββββββββββββββββββββββ© β cover.png β https://dev-to-uploads.s3.amazonaws.com/β¦ β ββββββββββββββββ΄βββββββββββββββββββββββββββββββββββββββββββ -
Upload multiple images or get Markdown: You can upload all PNG images in the current directory using
* .png. You can also get the Markdown formatted image tag directly by adding the--markdownflag.devpub upload architecture.png --markdownThis will output the Markdown ready to be pasted into your article:

Original source
This workflow is based on a blog post by Sarvar on the DEV Community platform. Sarvar shares the story of how a community contributor added image upload functionality to his devpub CLI tool, explaining the technical challenge of uploading images to Dev.to without a direct API endpoint and how it was solved.
Notes & variations
- Free tier alternative: There is no direct free tier alternative for a CLI tool that automates this specific Dev.to upload process. The manual upload via the Dev.to website is the standard, free method.
- Common pitfall: Forgetting to set the
DEVPUB_SESSION_COOKIEandDEVPUB_CSRF_TOKENin the.devpub/.envfile will cause the upload to fail. The tool needs these to authenticate with Dev.toβs web interface. - Tip for better results: Use the
--markdownflag when uploading images that you plan to use in your articles. This saves you the extra step of formatting the image link yourself.