0

Upload a single file with POST API

Hi all, 

Can please someone help me with the following API call within Ninox? What am I doing wrong?

I am trying to upload a document in a record and I call this http request from a record with a button.

let xMethod := "POST";
let xURL := "https://api.ninox.com/v1/teams/" + TeamID + "/databases/" + 'Database ID' + "/tables/" + 'Table ID' + "/records/" + 'record ID' + "/files/";
let xHeader := {
Authorization: "Bearer IADDMYKEY HERE",
'Content-Type': "multipart/form-data"    };
let xBody := "file=@/Users/virco/Downloads/ss.png";
do as server
let xResponse := http(xMethod, xURL, xHeader, xBody);
'API result' := text(xResponse.result)
end

When I run it I get "Internal Server Error"

 

These are the Ninox Instructions below. Not sure what I am doing wrong. Any help would be appreciated

 

curl https://api.ninox.com/v1/teams/Cf8fqfNeCaAvBrjkS/databases/zvdufqsrxwr2/tables/A/records/4/files

-X POST

-H 'Authorization: Bearer c0da1580-1a26-11ec-ba4d-f9d8817e4f95'

-H 'Content-Type: multipart/form-data'

-F 'file=@"/Users/anastasiya/Downloads/iStock-184877012.jpeg"'

 

PS: By mistake I added this post to Learn & Share section but I can't delete. Apologies for duplication.

4 replies

null
    • Ninox developper
    • Jacques_TUR
    • 1 yr ago
    • Reported - view

    ask to Axel Rothe , who created a Ninox REST API in JavaScript and shared his work on GitHub : see his post here 

    • Ninox developper
    • Jacques_TUR
    • 1 yr ago
    • Reported - view

    I also think that the new http functions (see here) could help you send multipart files, but I never use it.

    One thing is sure, it is not possible to download a file by giving directly its location on the computer disk. Otherwise you could empty a user's hard disk without him/her noticing. All browsers prohibit this. You have to use an interface where the user chooses the file, like for example the html input-file components (see here).

    In JavaScript, Ninox has a function that allows the selection of a file.

    #{
        NinoxDocumentInteraction.chooseFile((err, file)=> {
            //YOUR CODE WHEN FILE IS CHOSEN
        });
    }#
    
    • Axel_Rothe
    • 1 yr ago
    • Reported - view

    Are you trying to use the http function from within Ninox? I’ve only ever used axios or curl to send to Ninox, but not using NX Scripting Language. 
     

    I’d double check the header, since you have two different quote symbols: " and '

    consider reducing to just " in your header.

    Try using a curl from your terminal / powershell to make sure your url is correct and the file is accessible.

    • Ninox developper
    • Jacques_TUR
    • 1 yr ago
    • Reported - view

    It would be easier to help you if I could better understand what you want to do. Uploading a single file with the POST API is a solution to what?

Content aside

  • 1 yr agoLast active
  • 4Replies
  • 502Views
  • 3 Following