mirror of
https://github.com/complexcaresolutions/telegram-media-bot.git
synced 2026-03-17 17:23:42 +00:00
fix: use _payload JSON field for Payload CMS upload
Payload CMS REST API requires document data (alt, tenant, etc.) as a JSON string in a _payload form field, not as individual form fields. Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
This commit is contained in:
parent
7d78cbb208
commit
f148856b1d
1 changed files with 8 additions and 3 deletions
|
|
@ -100,9 +100,14 @@ class PayloadClient {
|
||||||
|
|
||||||
async uploadMedia(file: Buffer, filename: string, mimeType: string, options: MediaUploadOptions): Promise<MediaDoc> {
|
async uploadMedia(file: Buffer, filename: string, mimeType: string, options: MediaUploadOptions): Promise<MediaDoc> {
|
||||||
const formData = new FormData();
|
const formData = new FormData();
|
||||||
formData.append('alt', options.alt);
|
|
||||||
if (options.caption) formData.append('caption', options.caption);
|
// Payload CMS requires document data as JSON in the _payload field
|
||||||
formData.append('tenant', String(options.tenantId));
|
const payloadData: Record<string, unknown> = {
|
||||||
|
alt: options.alt,
|
||||||
|
tenant: options.tenantId,
|
||||||
|
};
|
||||||
|
if (options.caption) payloadData.caption = options.caption;
|
||||||
|
formData.append('_payload', JSON.stringify(payloadData));
|
||||||
|
|
||||||
const arrayBuffer = new ArrayBuffer(file.byteLength);
|
const arrayBuffer = new ArrayBuffer(file.byteLength);
|
||||||
new Uint8Array(arrayBuffer).set(file);
|
new Uint8Array(arrayBuffer).set(file);
|
||||||
|
|
|
||||||
Loading…
Reference in a new issue