Appearance
Image Uploaders
An image uploader appears in Settings ▸ Image ▸ Image Uploader next to Typora's own (PicGo, PicList, a custom command…). When the user picks it, Typora hands it the images to upload — on insert, from Upload Image in the image menu, for every image in a document, and from Test Uploader — and your main returns their URLs.
json
{
"id": "someone.s3",
"name": "S3 Uploader",
"version": "1.0.0",
"permissions": { "network": ["https://*.amazonaws.com"] },
"contributes": {
"imageUploaders": [
{ "id": "s3", "title": "Amazon S3", "description": "Uploads to the bucket set in the options." }
]
},
"main": "main.js"
}js
// main.js
export function activate(ctx) {
ctx.subscriptions.push(
typora.images.registerUploader("s3", async (images) => {
const urls = [];
for (const image of images) urls.push(await putObject(image.name, image.type, image.bytes));
return urls;
}),
);
}imageUploaders
| Field | Required | Description |
|---|---|---|
id | yes | Local id. Register the uploader with the same id. |
title | yes | Shown in the Image Uploader menu. |
description | One sentence for the store and Settings. | |
url | https:// page where users get the app or service it needs. Settings offers it as a download link. |
Image uploaders need main. main starts the first time one is used (onImageUploader:<id>).
The uploader
typora.images.registerUploader(id, uploader) registers a function that receives the images and returns a promise of their URLs, one per image and in the same order:
| Field of each image | |
|---|---|
name | File name, such as image.png. |
type | MIME type. |
path | Absolute path when the image is a file on this computer, otherwise null (pasted images). |
bytes | The image, as a Uint8Array. |
Throw an Error to fail; its message is shown to the user. Uploads may take up to 10 minutes.
Typora's Settings window has no document, so when the user presses Test Uploader there, Typora starts your main just for the upload and stops it afterwards. Don't rely on editor or document in an uploader.
Platforms
An uploader that drives a desktop app usually works on one platform. Set os in the manifest, and Typora lists the extension as unavailable elsewhere. The iPic sample is macOS-only: it talks to iPic through osascript with the process permission.
In the store
Tag image uploaders Image Uploader: Settings ▸ Image ▸ Image Uploader ▸ More from Extensions… opens extensions.typora.io/?tag=image-uploader.