photo
Save images to the Android system gallery.
photo.save
photo.save(options): Promise<void> saves one image to Pictures/SuperNode and resolves after publication. Regular projects and widget tasks are supported within their host process and task lifetimes. Android 10+ uses MediaStore to add app-owned media directly, without gallery read permission.
| Parameter | Type | Description |
|---|---|---|
url | string | URL | HTTP(S) image URL. |
headers | Readonly<Record<string, string>> | Optional URL request headers. |
data | Blob | ArrayBuffer | ArrayBufferView | Image bytes, including File and Node.js Buffer. |
filename | string | Optional filename, normalized to a single filename. |
Supply exactly one of url and data; headers belongs to URL requests. The SDK exports the PhotoSaveOptions union type. Empty data, invalid URLs, headers, filenames and invalid images raise errors.
Save a URL
import { photo } from "supernode";
await photo.save({
url: "https://example.com/photo.png",
filename: "photo.png",
});Headers and downloads
Pass authentication through headers. Downloads use streaming GET with up to 10 redirects; cross-origin redirects strip Authorization, Cookie and Proxy-Authorization. Requests use explicit headers independently of Android app cookies and caches. Each network read has a 30-second idle timeout.
import { photo } from "supernode";
await photo.save({
url: "https://example.com/private/photo.jpg",
headers: { Authorization: "Bearer YOUR_TOKEN" },
});Save bytes
import { readFile } from "node:fs/promises";
import { photo } from "supernode";
await photo.save({ data: await readFile("images/result.png"), filename: "result.png" });Filename priority is explicit filename, File.name, the final URL filename, then a generated name. Android validates the image format and MIME from its content and preserves the original bytes.
Large images and errors
A dedicated RPC connection transfers chunks of at most 512 KiB with acknowledgements; Android writes them incrementally to a temporary file. URL images stream during download; in-memory byte sources create a Blob snapshot. Total size depends on available storage and task lifetime. Failures and disconnects clean up transfers and pending media; the next app startup recovers abandoned tasks.
Handle failures with try/catch. Error prefixes include PHOTO_PERMISSION_DENIED, PHOTO_DOWNLOAD_FAILED, PHOTO_TRANSFER_FAILED, PHOTO_INVALID_IMAGE, and PHOTO_SAVE_FAILED. SDK argument errors throw TypeError.
import { photo } from "supernode";
try {
await photo.save({ url: "https://example.com/photo.png" });
} catch (error) {
console.error(error);
}