Webservices Put Examples
Creating Samples (PUT)
As I mentioned above you cannot use your browser to send PUT requests to a server, the following examples are using curl. Let's say you want to create ten samples named sample-XX where XX is a number from 01-10. The format for uploading information is also tab separated so I'll start of by issuing a GET request to the server getting a template file for the samples. And I will also like to share the samples to my first project Little piggy project with the id 2.
Getting the file with curl will look like this in (*nix) environments
curl "http://localhost:8080/proteios/resource/projects/2/samples?username=john&password=cow&select=Name&select=ExternalId&select=OriginalQuantity" -o samples.txt
Open the file samples.txt and enter the sample names, one on each row like this
ExternalId Name OriginalQuantity a1 sample-01 100 a2 sample-02 100 a3 sample-03 100 a4 sample-04 100 a5 sample-05 100 a6 sample-06 100 a7 sample-07 100 a8 sample-08 100 a9 sample-09 100 a10 sample-10 100
Now uploading the file to the same context as we got the template from will create one sample for each row and share that sample to our project. Issuing a PUT request looks like this
curl -T samples.txt "http://localhost:8080/proteios/resource/projects/2/samples?username=john&password=cow"
If you do not want to share the samples to any project it's only a matter of uploading them to the samples context like this
curl -T samples.txt "http://localhost:8080/proteios/resource/samples?username=john&password=cow"
Creating Files (PUT)
In version 2.7 the webservice allows you to register external files. You do this in the same way as you created samples above.
curl "http://localhost:8080/proteios/resource/files?username=john&password=cow&select=Name,UniformResourceIdentifier&limit=0" -o files.txt
Open the file files.txt and enter names and URI's to files you want to register, remember to use the tab key to seperate the values. Some editors, like emacs, can convert tabs into spaces.
Name UniformResourceIdentifier test.txt file:///tmp/test.txt
Save the file and run
curl -T files.txt "http://localhost:8080/proteios/resource/files?username=john&password=cow"
You should now have registered the file /tmp/test.txt with proteios.
Security note!
All files readable by the tomcat user are readable through proteios if registered. This is a potential security issue if Proteios SE is used on a public server. Either the webservice should be disabled or you must ensure that files that should not be readable through Proteios SE are NOT readable by tomcat.
Create Files Within a Project
In the above example files end up in the authenticated users home directory. If you want files to end up in a project directory just change the URL like this
FROM: http://localhost:8080/proteios/resource/files?username=john&password=cow TO: http://localhost:8080/proteios/resource/projects/ID/files?username=john&password=cow
where the ID is the project id you want to use.
Upload Local Files
Uploading a file requires an existing file item on the server. Once you know the id of that object you can upload a file to it with
curl -T local.file "http://localhost:8080/proteios/resource/files/FILE_ID?username=john&password=cow
where FILE_ID is the known file item id.
Attachments
-
uploadFileToProSE.sh
(1.5 KB) -
added by gregory 18 months ago.
Example shell script for uploading files to ProSE
