this post was submitted on 09 Sep 2023
4 points (100.0% liked)

JavaScript

1968 readers
1 users here now

founded 1 year ago
MODERATORS
 

async MediaUpload(photos : any[]) { const client = await this.Login() const full_photo_urls : string[] = photos.map((item) => item.full) let image_ids : string[] = []; full_photo_urls.forEach(async (image_url) => { const image_blob = await fetch(image_url).then(res => res.blob()) try { console.log("images are about to be posted!"); const image_res = await client.postMediaAttachment({file: image_blob}) console.log("Images were posted here"); console.log(image_res); } catch (error) { console.error(error); } }) return image_ids;

Runs Error block which results in this

{ failed: true, json: { id: '111037763715692057', type: 'image', url: 'https://files.botsin.space/media_attachments/files/111/037/763/715/692/057/original/c46fd6ce6b892c66.jpeg', preview_url: 'https://files.botsin.space/media_attachments/files/111/037/763/715/692/057/small/c46fd6ce6b892c66.jpeg', remote_url: null, preview_remote_url: null, text_url: null, meta: { original: [Object], small: [Object] }, description: null, blurhash: 'UEHo8yIm%gV?9Exv%fM{?u~qM_D%xvITM{xa' }, path: 'media', response: Response { [Symbol(realm)]: null, [Symbol(state)]: { aborted: false, rangeRequested: false, timingAllowPassed: true, requestIncludesCredentials: true, type: 'default', status: 200, timingInfo: [Object], cacheState: '', statusText: 'OK', headersList: [HeadersList], urlList: [Array], body: [Object] }, [Symbol(headers)]: HeadersList { cookies: null, [Symbol(headers map)]: [Map], [Symbol(headers map sorted)]: null } }, status: 200, rateLimit: 30 }

I am really confused given it gives me a status code 200 which means OK, but still says it failed??? I also used my debugging to understand this is the line where the error occurs

const image_res = await client.postMediaAttachment({file: image_blob})

also ignore the fact imageres is unused, I removed the code after it for testing since to ensure nothing else was causing the error

top 2 comments
sorted by: hot top controversial new old
[โ€“] khall@programming.dev 2 points 1 year ago (1 children)

One thing to check is the mime-types of the uploaded file and the source. I had a squirrel-y issue with my S3 bucket src files not having the correct content type

[โ€“] skymtf@lemmy.blahaj.zone 1 points 1 year ago

How exactly would I check that, the function for uploading only accepts a type of a blob or a file