@dazl/wix-media-client

中文文档
1.7.0发布于 2026/05/10UNLICENSEDES Module零依赖近 30 天下载 1万

Browser client for Wix Media Platform - file uploads and image transformations

原始使用文档
文档目录13 节
  1. Features
  2. Quick Start
  3. List Files
  4. Upload File
  5. Image URLs
  6. API Reference
  7. listFiles(options): Promise<ListFilesResponse>
  8. uploadFile(options): Promise<UploadResult>
  9. getFileUrl(mediaHost, file, commands?): string
  10. isImageMimeType(mimeType): boolean
  11. createResponsiveImageSet(mediaHost, path, options): Record<…
  12. createSrcSet(mediaHost, path, options): string
  13. License

@dazl/wix-media-client

Browser client for Wix Media Platform via dazl API server.

Features

  • List media files with cursor-based pagination
  • File upload with progress tracking and automatic media record creation
  • Image URL generation with transformations (fill, fit, crop)
  • Direct file URL generation for non-images
  • Responsive image set generation
  • TypeScript, zero dependencies, browser-safe

Quick Start

All API functions take an endpoint pointing to the media API. The client appends sub-routes internally.

const endpoint = "https://api.dazl.dev/api/media";

List Files

import { listFiles } from "@dazl/wix-media-client";

const result = await listFiles({ endpoint, projectId: "project-uuid" });

// Filter by type
const images = await listFiles({ endpoint, projectId: "project-uuid", mimeType: "image/" });

// Paginate
const page2 = await listFiles({ endpoint, projectId: "project-uuid", cursor: result.nextCursor! });

Upload File

import { uploadFile } from "@dazl/wix-media-client";

const result = await uploadFile({
  endpoint,
  projectId: "project-uuid",
  file: selectedFile,
  onProgress: (progress) => console.log(`${progress.toFixed(0)}%`),
});

The upload flow:

  1. POST {endpoint}/upload-configuration — gets a presigned Wix upload URL
  2. PUT file directly to Wix CDN (with progress tracking via XHR)
  3. POST {endpoint} — creates a media record in the database

Image URLs

import { getFileUrl } from "@dazl/wix-media-client";

const MEDIA_HOST = "wixmp-abc123.appspot.com";

// Image with transforms
const thumbnail = getFileUrl(MEDIA_HOST, { path: "/projects/xxx/photo.jpg", mimeType: "image/jpeg" }, {
  operation: "fill",
  width: 200,
  height: 200,
  quality: 85,
  format: "webp",
});

// Fit within bounds — both `width` and `height` are required by the wixmp
// image service. `fit` preserves aspect ratio so the actual output is bounded
// by whichever axis hits first.
const url = getFileUrl(MEDIA_HOST, { path: "/projects/xxx/photo.jpg", mimeType: "image/jpeg" }, {
  operation: "fit",
  width: 800,
  height: 800,
});

// No transform commands — defaults to fit 1000x1000 (handy for LLM URL fetchers).
const defaultUrl = getFileUrl(MEDIA_HOST, { path: "/projects/xxx/photo.jpg", mimeType: "image/jpeg" });

// Non-image (returns direct URL automatically)
const pdfUrl = getFileUrl(MEDIA_HOST, { path: "/projects/xxx/doc.pdf", mimeType: "application/pdf" });

API Reference

listFiles(options): Promise<ListFilesResponse>

OptionTypeDefaultDescription
endpointstringrequiredMedia API endpoint
projectIdstringrequiredProject identifier
mimeTypestring-Filter by MIME type prefix (e.g., 'image/')
cursorstring-Cursor token for next page
pageSizenumber20Items per page

Returns { items: MediaItem[], nextCursor: string | null, total: number }

uploadFile(options): Promise<UploadResult>

OptionTypeDefaultDescription
endpointstringrequiredMedia API endpoint
projectIdstringrequiredProject identifier
fileFilerequiredFile to upload
acl'public' | 'private''public'Access control
onProgress(progress: number) => void-Progress callback (0-100)
createMediaRecordfalse-Set to false to skip DB record creation

Returns { success, path, filename, descriptor }

getFileUrl(mediaHost, file, commands?): string

Generate the appropriate URL for a file. Scalable images (PNG, JPEG, GIF, WebP) go through the Wix image service with transforms. Non-scalable images (SVG, ICO) and non-images get a direct URL.

When commands is omitted, raster images get fit 1000×1000 by default (a console.warn is emitted to encourage callers to specify their own). The wixmp image service requires both width and height for fit/fill/crop operations — single-dim transforms return HTTP 400 missing h.

isImageMimeType(mimeType): boolean

createResponsiveImageSet(mediaHost, path, options): Record<number, string>

Each entry in dimensions is generated as fit dimension×dimension (square cap). fit preserves aspect ratio, so the actual output is bounded by whichever axis hits first.

createSrcSet(mediaHost, path, options): string

License

UNLICENSED

版本与发布记录

@dazl/wix-media-client 共发布 13 个版本,首次发布于 2025/12/11;过去 12 个月发布了 13 个版本。

版本发布日期距今
1.7.0latest2026/05/106 个月前
1.6.02026/04/206 个月前
1.5.02026/04/206 个月前
1.4.22026/03/247 个月前
1.4.12026/03/247 个月前
1.4.02026/03/247 个月前

关于 @dazl/wix-media-client 的常见问题

@dazl/wix-media-client 是什么?

Browser client for Wix Media Platform - file uploads and image transformations

如何安装 @dazl/wix-media-client?

在项目目录运行 npm install @dazl/wix-media-client,或使用 pnpm add / yarn add / bun add。

@dazl/wix-media-client 支持 TypeScript 吗?

该包的 package.json 没有声明类型入口。需要类型提示时,可以在 npm 上查找社区维护的 @types/dazl__wix-media-client 是否存在。

@dazl/wix-media-client 支持 ESM 还是 CommonJS?

以 ES Module 形式发布,推荐使用 import 引入。在 CommonJS 项目中,Node.js 20.19+ / 22.12+ 可以直接 require() 不含顶层 await 的 ES Module,更早的版本需要改用动态 import()。

@dazl/wix-media-client 需要什么版本的 Node.js?

package.json 的 engines 字段要求 Node.js >=22。版本不符时 npm 默认只给出警告,开启 engine-strict 后会拒绝安装。

@dazl/wix-media-client 可以商用吗?

@dazl/wix-media-client 使用 UNLICENSED 许可。作者声明为 UNLICENSED,即不授予公开使用许可(与公共领域的 Unlicense 不同)。使用前需获得作者授权。以上为概括,不构成法律意见,请以许可原文为准。

@dazl/wix-media-client 的下载量有多少?

根据 npm 官方下载统计,@dazl/wix-media-client 在 2026/10/12 – 2026/11/10 这 30 天内被下载 10,165 次,日均约 339 次。下载量会把 CI 构建、镜像同步和作为其他包依赖的安装一并计入,适合横向比较热度,不能直接等同于使用人数。

@dazl/wix-media-client 还在维护吗?

最新版本 1.7.0 发布于 2026/05/10(6 个月前);至今共发布 13 个版本,其中过去 12 个月发布了 13 个;首次发布于 2025/12/11。发布频率只是参考信号:功能稳定的工具可能很少需要更新,建议结合源码仓库的 issue 和提交记录判断。