-
-
Notifications
You must be signed in to change notification settings - Fork 54
Open
Description
I can't upload any images whatsoever to Mastodon
I've tried so many different methods, this stupid thing just keeps returning
MastoHttpError: Error processing thumbnail for uploaded media
at HttpNativeImpl.<anonymous> (file:///usr/local/server/src/function/node_modules/masto/dist/index.js:1000:24)
at Generator.next (<anonymous>)
at fulfilled (file:///usr/local/server/src/function/node_modules/masto/dist/index.js:73:58)
at process.processTicksAndRejections (node:internal/process/task_queues:95:5)so idk. I'm on ^6.10.1, posting statuses is fine, and I've tried giving it a thumbnail (which says there can't be one for images), I've tried giving it a local file, a blob, everything, and it still fails over and over.
async uploadMediaAttachmentCustom(
mediaAttachment: MastodonMediaAttachment
): Promise<mastodon.v1.MediaAttachment> {
const mastodonClient = this.getMastodonApiClient();
let file: Buffer | Blob;
let fileMimeType: string;
let thumbnail: Buffer | Blob | undefined;
let thumbnailMimeType: string | undefined;
// Handle main file
this.log(`Handling main file`);
if (typeof mediaAttachment.file === 'string') {
this.log(
`Downloading image from URL, ${mediaAttachment.file.slice(0, 100)}`
);
const result = await this.appwriteManager.imageUtils.downloadBlobFromUrl(
mediaAttachment.file
);
file = result.blob;
fileMimeType = result.mimeType;
} else if (mediaAttachment.file instanceof Blob) {
this.log(`Handling Blob file`);
file = mediaAttachment.file; // Use the Blob directly instead of converting
fileMimeType = mediaAttachment.file.type;
} else {
throw new Error('Invalid file type for media attachment');
}
// Handle thumbnail
if (mediaAttachment.thumbnail) {
this.log(`Handling thumbnail`);
try {
if (typeof mediaAttachment.thumbnail === 'string') {
this.log(
`Downloading thumbnail from URL, ${mediaAttachment.thumbnail.slice(0, 100)}`
);
const result =
await this.appwriteManager.imageUtils.downloadBlobFromUrl(
mediaAttachment.thumbnail
);
thumbnail = result.blob;
thumbnailMimeType = result.mimeType;
} else if (mediaAttachment.thumbnail instanceof Blob) {
this.log(`Handling Blob thumbnail`);
thumbnail = mediaAttachment.thumbnail; // Use the Blob directly
thumbnailMimeType = mediaAttachment.thumbnail.type;
}
} catch (error) {
this.log(`Error downloading thumbnail: ${error}`);
thumbnail = undefined;
thumbnailMimeType = undefined;
}
}
const mediaParams: mastodon.rest.v2.CreateMediaAttachmentParams = {
file:
file instanceof Buffer
? new Blob([file], { type: fileMimeType })
: file,
thumbnail:
thumbnail instanceof Buffer
? new Blob([thumbnail], { type: thumbnailMimeType })
: thumbnail,
description: mediaAttachment.description,
focus: mediaAttachment.focus,
};
this.log(
`Uploading media with params: ${JSON.stringify(
{
fileType: fileMimeType,
thumbnailType: thumbnailMimeType,
hasFile: !!file,
hasThumbnail: !!thumbnail,
description: mediaAttachment.description,
focus: mediaAttachment.focus,
},
null,
2
)}`
);
const response = await mastodonClient.v2.media.create(mediaParams);
return response;
}Metadata
Metadata
Assignees
Labels
No labels