-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
docs: add cURL info and update parameters
- Loading branch information
Showing
1 changed file
with
48 additions
and
21 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -19,24 +19,11 @@ You can use the API as unauthenticated (anonymous) or [authenticated](#how-to-au | |
| Remove uploaded file later - with no self destruct option | ❌ No | ✅ Yes | | ||
| Access private files - if user is allowed | ❌ No | ✅ Yes | | ||
|
||
### How to authenticate ? | ||
### Where to find the API token ? | ||
|
||
If you do have an account, head over the "My Account" page and | ||
grab your "API Token" from there. | ||
|
||
Now, if every requests you make to the API, just add the `Authorization` header, where its value is the API token you got from earlier. | ||
|
||
#### Simple example using `fetch` | ||
|
||
```typescript | ||
const response = await fetch("https://drive.cattolabs.com/api/...", { | ||
// ... | ||
headers: { | ||
authorization: "api-token-you-got-here" | ||
} | ||
}); | ||
``` | ||
|
||
### Get a workspace ID | ||
|
||
> TODO | ||
|
@@ -49,24 +36,28 @@ To use [drive.cattolabs.com](https://drive.cattolabs.com) with ShareX, you have | |
|
||
Head over to "Destinations" > "Custom uploader settings" ; | ||
|
||
### Manual | ||
From here, you can either [create a new custom uploader manually](#manual) or simply use a pre-made one we give you: [anonymous upload](#pre-made-anonymously-upload-public-files). | ||
|
||
#### Manual | ||
|
||
- Click on "New" to create a new uploader. Name it as you want, we'll go with `drive.cattolabs.com` here ; | ||
- Set the "Destination type" to `Image uploader` and `File uploader`, we currently don't support `Text uploader` ; | ||
- Set the "Method" to `PUT` ; | ||
- Set the "Request URL" to `https://kcpxeoxkmblpivpgwdsm.supabase.co/functions/v1/upload-file`, (for some reason, ShareX throws on redirections so `https://drive.cattolabs.com/api/files` doesn't work) ; | ||
- Set the "Request URL" to `https://kcpxeoxkmblpivpgwdsm.supabase.co/functions/v1/upload-file`, (for some reason, ShareX throws an error on redirection so `https://drive.cattolabs.com/api/workspace/upload` doesn't work) ; | ||
- Keep "URL parameters" empty ; | ||
- For "Headers", leave empty if you want to upload as anonymous, else add `Authorization` and as value, [your API key](#using-the-api) ; | ||
- For "Headers", leave empty ; | ||
- Keep "Body" as `Form data (multipart/form-data)`, below you're able to add form data parameters | ||
|
||
> `private` as name and `0` as value to make all your uploaded files public. | ||
> If you're authenticated, uploaded files will be at the root of your drive by default, you can override that behavior by adding `workspace_id` as name and [any workspace ID](#get-a-workspace-id) as value to make all uploads go there. | ||
> `private` as name and `0` as value to make all your uploaded files public. If you're authenticated to an account, the default value will be `1` and `0` if you're anonymous. | ||
> If you want to upload to an account, pass the `api_token` parameter followed by the value of the [account's API token](#where-to-find-the-api-token). | ||
> By default, uploaded files will be in the root workspace of the account. | ||
> You can override that behavior by adding `workspace_id` as name and [any workspace ID](#get-a-workspace-id) as value to make the upload go there. | ||
- Set the "File form name" to `files` ; | ||
- Set the "URL" to `https://drive.cattolabs.com/api/file/{json:data.uploaded[0].id}` | ||
- Set the "Error message" to `{json:message}` | ||
|
||
### Pre-made: Anonymously upload public files | ||
#### Pre-made: Anonymously upload public files | ||
|
||
```json | ||
{ | ||
|
@@ -85,7 +76,43 @@ Head over to "Destinations" > "Custom uploader settings" ; | |
} | ||
``` | ||
|
||
## Developing | ||
### Integration with cURL | ||
|
||
You can simply send files through your terminal using cURL. | ||
|
||
In these examples, let's say you want to upload two files located at `./screen1.png` and `/tmp/image.jpg`. | ||
|
||
#### Upload as anonymous | ||
|
||
```bash | ||
curl -L \ | ||
-X PUT \ | ||
-F '[email protected]' \ | ||
-F 'files=@/tmp/image.jpg' \ | ||
https://drive.cattolabs.com/api/workspace/upload | ||
``` | ||
|
||
#### Upload as authenticated to a certain workspace | ||
|
||
```bash | ||
curl -L \ | ||
-X PUT \ | ||
-F "api_token=YOUR_API_TOKEN" \ | ||
-F 'workspace_id=SOME-WORKSPACE-ID-123456789' \ | ||
-F 'private=0' \ | ||
-F '[email protected]' \ | ||
-F 'files=@/tmp/image.jpg' \ | ||
https://drive.cattolabs.com/api/workspace/upload | ||
``` | ||
|
||
If you want to upload to your root workspace, you can remove the `workspace_id` | ||
parameter, it'll take the root workspace by default. | ||
`workspace_id` can be found using [this guide](#get-a-workspace-id). | ||
|
||
`private` defaults to `1` if not passed. If you want to make publicly | ||
accessible uploads, you might have to change it to `private=0`. | ||
|
||
## Run locally | ||
|
||
```bash | ||
pnpm dev | ||
|