Hi!
I am learning on how to upload files to my database.
${UserAndPassword} Create Dictionary username=Name password=Password
${response} POST url=site.com/authorize json=${UserAndPassword} #I want to get auth token here
${accessToken} Set Variable ${response.json()}[accessToken]
${headers} Create Dictionary accessToken=${accessToken} #Adding auth token to headers
${file}= Get File For Streaming Upload ${CURDIR}/MyFileInZip.zip
${response2} POST url=http://192.168.25.24:9090/api/documents data=${file} headers=&{headers}
I got error 403 An Authentication object was not found in the SecurityContext
What am I doing wrong? (And how to make code on forum look pretty?)
Also if you are pushing the file as raw data like that, you probably also need to include a mime type in the header.
Does the DB’s API support raw file data or do you need to encode it (base64?)?
Do you need to embed the file content within a JSON request?
if it does it might need a document id in the header?
There should be documentation about uploading a file, it’s one of the trickier things to do with a NoSQL database, make sure you have everthing the documentation asks for, or better yet find a working example to compare with.
I am not sure if you should use &{headers} (the dictionary object). Maybe you should use ${headers} (the dictionary content). Disclaimer: I did not checked documentation.
About formatting, in the message editor you have style buttons, like, Bold, Italic, … The one to mark code is </>. Control-e is also the shortcut.
I use for inline code style, text enclosed in a single ` (back tick). For blocks of code like below, you can write in the first line and the last, three back ticks, ```.
${response2} POST url=http://192.168.25.24:9090/api/documents data=${file} headers=${headers}
You don’t need sessions, they make your life easier as you can carry headers across posts rather than having to set them every time.
Also when the server sets a header like a auth token or cookie it will remember and pass it back for you like a browser does.
If you are doing a single get don’t bother with a session, if you are doing several posts with the first one being an AUTH post, then you probably want a session.