Articles

Store an image for an article

Stores an image for this article and answers with the URL it is served at, so whatever writes the article never needs somewhere of its own to host one. Needs content: write.

Two ways in, chosen by the body:

  • source_url: Commune downloads the image and stores a copy. For an image you hold as a link, including a generated one on a link that will expire. It has to be a public http or https URL on the standard port; private and local network addresses are refused, redirects included.
  • content_type: Commune answers with a one-time upload URL and the image's final url. PUT the file's bytes to upload.url with the upload.headers, before upload.expires_at. The bytes go straight to storage, so a file on disk never has to pass through a model or through this API. Until the upload is made, url answers 404.

Either way the image is a JPEG, PNG, WebP or GIF of at most 10MB, and the article itself is not changed: put the url in the body's Markdown (![alt](url)) or in image_url with Update an article (PATCH /articles/{article}).

post/articles/{article}/images

Request

  • Base URL: https://api.usecommune.com
  • URL: https://api.usecommune.com/articles/{article}/images
  • Auth: one of:
    • HTTP bearer
    • OAuth 2 (authorization code, authorization URL https://usecommune.com/api/oauth/authorize, token URL https://usecommune.com/api/oauth/token, scopes: content:write)

Request body

source_urlstring uri

A public http or https URL of the image for Commune to download and store.

content_type'image/jpeg' | 'image/png' | 'image/webp' | 'image/gif'

The type of the file you will upload yourself. The answer carries the upload URL.

Example request

{
  "source_url": "https://example.com/chart.png"
}

Response

The stored image, or for an upload, where it will be once the file is uploaded.

object'article_image' required

Always article_image.

urlstring uri required

Where the image is served. Use it in the article's Markdown or as its image_url. For an upload, it answers 404 until the file is uploaded.

content_type'image/jpeg' | 'image/png' | 'image/webp' | 'image/gif' required

The image's type. For a download, read from the bytes themselves, whatever the source said.

size_bytesinteger nullable required

How large the stored image is. Null for an upload, whose size is not known until the file arrives.

source_urlstring nullable required

The URL the image was downloaded from. Null for an upload.

Changes

No recorded changes to this operation across all 1 revision of this API.