Table of Contents |
---|
...
As you need authentication to perform these operations, except for GET in some cases, you need to authenticate using OAuth. To do this, you must send a GET request to the path '/api-ops/login/username/{username}/password/{password}', replacing the parameters in {curly braces}.
If the credentials are correct, you will receive an access token, "access_token".This is the token you will use in all your requests as an authentication header.
...
NOTE: Remember to include "Bearer" before the access token.
CRUD Operation
...
Uploading a file (POST)
To upload a post, you must make a POST request to the 'controlpanel/binary-repository' endpoint, with two parameters in the body:
...
You will receive in return an identifier that can be used to edit and upload the file later.
...
Downloading a file (GET)
To download a binary file, you need to have that file's identifier, then make a GET request to the '/controlpanel/binary-repository/{id}' endpoint, replacing id with the file's identifier, which will be returned by the platform after every insert.
...
If you write this link in a browser, you will receive the binary file instead of the JSON.
...
Editing a file (PUT)
If you have permissions to modify a file, then you can do it in the '/controlpanel/binary-repository/{id}' endpoint, with PUT method, replacing id with the binary file's identifier.
...
The file will be updated if you receive a HTTP 202.
...
Deleting a file (DELETE)
Lastly, to delete a file on which you have permissions, you need to do a DELETE request to the '/controlpanel/binary-repository/{id}' endpoint, replacing id with the binary file's identifier.
Same as with the PUT, you will receive a HTTP 202 if everything went fine and the file was deleted from the platform.
...
Using the Java API
If you intend to work with binaries from Java, there is an API you can use.
...
- Client: BinaryRepositoryClient.java , in charge of implementing the binary repository CRUD via REST.
- Model: BinaryDataFile.java , this model will be used to encapsulate the binary file that will be requested to the platform.
...
Client initialization
You will need to initialize the client, providing your user and password, along with the server or domain where the platform is deployed, as the arguments:
...
The client will reach OAuth authentication with your credentials.
...
Uploading a File
To upload a file, you only need to call the client's addBinaryFile(File file, String metadata) method. The maximum file size is 50MB.
...
Downloading a File
To download a file, you must use the getBinary(String id) method, which will return a BinaryDataFile -type object, with the binary encapsulated in it.
...
Editing a File
To update a file, you must use the updateBinaryFile(String id, File newFile, String newMetadata) method. The maximum file size is50MB.
...
Deleting a File
Lastly, to delete a file, you must call the removeBinaryFile(String id) method.
...