UNPKG

@wordpress/media-utils

Version:
26 lines (25 loc) 811 B
/** * WordPress dependencies */ import apiFetch from '@wordpress/api-fetch'; /** * Internal dependencies */ import { flattenFormData } from './flatten-form-data'; import { transformAttachment } from './transform-attachment'; export async function uploadToServer(file, additionalData = {}, signal) { // Create upload payload. const data = new FormData(); data.append('file', file, file.name || file.type.replace('/', '.')); for (const [key, value] of Object.entries(additionalData)) { flattenFormData(data, key, value); } return transformAttachment(await apiFetch({ // This allows the video block to directly get a video's poster image. path: '/wp/v2/media?_embed=wp:featuredmedia', body: data, method: 'POST', signal })); } //# sourceMappingURL=upload-to-server.js.map