how to upload image? (lemmy fetch api)

https://lemmy.world/post/25129991

how to upload image? (lemmy fetch api) - Lemmy.World

yup. me again… client [https://github.com/lgor360/oldemmi/blob/dev/settings.html#L175-L202] proxy server (for cors) [https://github.com/lgor360/oldemmi/blob/main/api/form.js]

It might not help because it’s in svelte and it doesn’t look like you’re using lemmy-js-client, but this is an example of how I do it in Alexandrite using lemmy-js-client. The onPaste function handles the paste event on the markdown editor textarea when someone pastes with an image in their clipboard, and the onFileInputChange is the change event for an <input type=“file” /> element so when someone selects a file it uploads and the input’s label can be styled like a button. Here is the client’s fetch function which handles the authorization header and whatnot. You can upload client-side without a proxy server for any instance running a newer version of Lemmy than like… 0.19.0? I didn’t want to be responsible for proxying image uploads so I waited to add image uploading in Alexandrite until I could do the uploads directly client side.
lemmy-js-client

A javascript / typescript client for Lemmy. Latest version: 0.20.0-search-combined.1, last published: 15 days ago. Start using lemmy-js-client in your project by running `npm i lemmy-js-client`. There are 4 other projects in the npm registry using lemmy-js-client.

npm
i cant install lemmy-js-client because i hav js. not node.js. i already tried some CDN and ESM libraries but it needs exports from node.js. i also tried to create some sort of lemmy-js-proxy (server with lemmy-js-client) which i would fetch through my site with the js but… JS CANT FETCH IT BECAUSE 404! i dont know why…