api (write plugin) upload - A valid login session was not found

  • how upload via api?
    here the c# code:

    var restClient = new RestSharp.RestClient(baseUrlApiV2); 
    var request = new RestSharp.RestRequest("/util/upload", RestSharp.Method.POST);
    request.AlwaysMultipartFormData = true;
    request.AddHeader("Content-Type", "multipart/form-data");
    request.AddHeader("Authentication", token);
    request.AddHeader("Authorization", token);
    request.AddFile("file[]", @"D:\phpbbAtach\54_0df4f16285a8bce30059e548f506fdf1", "image/png");
    IRestResponse response = restClient.Execute(request);
    var content = response.Content.Dump();

    the raw request:

    POST http://mysite.com/api/v2/util/upload HTTP/1.1
    Content-Type: multipart/form-data
    Authentication: xxxxxxxx-xxxx-xxxx-xxxx-xxxxxxxxx
    Authorization: xxxxxxxx-xxxx-xxxx-xxxx-xxxxxxxxx
    Accept: application/json, application/xml, text/json, text/x-json, text/javascript, text/xml
    User-Agent: RestSharp/
    Host: tchumim.com
    Content-Length: 24977
    Accept-Encoding: gzip, deflate
    Connection: Keep-Alive
    Content-Disposition: form-data; name="files[]"; filename="54_0df4f16285a8bce30059e548f506fdf1"
    Content-Type: image/png

    the response (401):

    {"code":"not-authorised","message":"A valid login session was not found. Please log in and try again.","params":{}}

  • Admin

    Are you using Bearer authentication with a user or master token? If master token, a uid must be provided in the payload under the key _uid.

  • thank! right, its a master token, but even after I added the parameter, yet the same response!

    Content-Disposition: form-data; name="_uid"
    Content-Disposition: form-data; name="file[]"; filename="54_0df4f16285a8bce30059e548f506fdf1"
    Content-Type: image/png

  • now i have tried with a user token, and same response. other call api works.

    nodebb version 1.7.3

  • I have no choice but to do so with forms-authentication 😞



Looks like your connection to NodeBB was lost, please wait while we try to reconnect.