api/admin/upload/file always 401
-
I've implemented several endpoints of my nodebb forum into an app and they work fine. But somehow I can't seem to upload a file because it always gives either a cors error or a 401 unauthorized error
I have no problems with cors on other endpoints.
Can anyone give a good example how to use this endpoint with fetch?
Right now I have: (the image being a base64 string)
return await fetch(Rapi + `post/upload?_uid=1`, { method: 'POST', body: JSON.stringify({ files: [image] }), headers }).then((response: any) => response.json());
-
@martijn-michel that url should be Rapi + 'admin/upload/file?_uid=1'
both endpoints dont work -
What headers are you passing in? What do you see in the server logs? Where are you sending this fetch request from?
-
l I think you need to provide the X-Csrf-Token
-
@pitaj said in api/admin/upload/file always 401:
X-Csrf-Token
ok, and what would be the value of that?
-
ive found this post, but i dont understand how to get a csrf token
https://community.nodebb.org/topic/6932/how-to-get-a-csrftoken-from-an-api-req-object/4