Integrating dStor into your application consists of a few simple steps.
Creating an API key (optional)
The API key is a token that the user can use to get a Access Token which will allow your application be able to interact with the dStor API.
Users can add multiple API keys as needed, as well as remove them.
API Keys should be treated with care and never exposed to ensure account security.
Using your dStor account login credentials or using the API key to acquire a temporary access token.
Attaching the temporary token to upload requests
The purpose of using the temporary access token model is to reduce reads to the dStor database, thereby ensuring that the system is able to remain performant even with a large number of users and applications uploading content.
Creating API Keys
In the dStor dashboard, click on the "Account" tab:
Now click the "Add" button to the top-right of the "Developer API Keys" table:
This opens a modal for you to set a description of what the API key will be used for, and set a date when you would like the API key to expire. The default is 365 days but can be set to expire sooner or later depending on your particular security needs. Then press the "Add" button:
The new API key, with its description and expiration, should now show up in your "Developer API Keys" table. In the "key" column you will see a truncated version of the API key. Click the copy icon next to the key in order to add the key to your clipboard for later use:
This temporary access token is what you will attach to your uploads to get new content hosted on dStor.
Acquire a Temporary Access Token with Login Credentials
As an alternative to the API key form, you can request a temporary access token by using your normal dStor login credentials by sending a POST request to the following endpoint:
https://api.dstor.cloud/​v1​/dev​/temp-token
The body of the request should look like the following:
Again, this temporary access token will be attached to our upload requests in order to host new files to the dStor network
Uploading a File to dStor
Now that you have received your temporary access token, we will use it to upload a file to dStor. We will be sending a POST request to the following endpoint:
The following headers are optional. If you do not specify which folder to upload to, the API will upload it to your root folder:
"x-dstor-parent-id": number // ID of containing folder
"x-dstor-folder-path": string // path of containing folder
"x-dstor-comment": string // optional, useful for metadata purposes
Please note that only the parent folder ID OR path is required, do not include both.
Additionally, you will need to set the Authorization as a bearer token with the temporary access token that you received in the previous section.
Naturally, your file should be uploaded as form data, so that your complete upload request should look something like the following:
The hash property, specifically, is what you will use in your app to access the file. If the upload was successful then you should see the file show up in your dashboard within a few seconds:
In order to access the file you will simply navigate to the following endpoint, with the has attached to the end: