跳到主要内容

Sketch 插件实现图层导出图片并上传

· 阅读需 1 分钟
SleepyZone

图层导出 buffer:

import SketchDom from 'sketch/dom';
import UI from 'sketch/ui';

const document = SketchDom.getSelectedDocument();
const { layers, length, isEmpty } = document.selectedLayers;

const layer = layers[0];

const options = { formats: 'png', output: false }
const buffer = SketchDom.export(layer, options);

buffer 上传:

const formData = new FormData();

formData.append('file', {
data: buffer,
fileName: `${Date.now()}.png`,
mimeType: 'image/png'
}, `${Date.now()}_glaze_layer_img.png`);

return fetch(url, { method: 'POST', body: formData })