Content
View differences
Updated by Andreas Pfohl over 3 years ago
Julien from Nextcloud provided us with the basic necessary [steps](https://cloud.nextcloud.com/s/Mp6FRfeGTedMXaX) for getting all the data that the front-end needs for directly uploading to Nextcloud. I copy his explanation below:
### Create shared access/link
```text
curl -H "Authorization: Bearer USER_OAUTH_TOKEN" \
-H "ocs-apirequest: true" \
-H "content-type: application/json" \
-H "Accept: application/json" \
-X POST \
-d '{"shareType":3,"label":"OPTIONAL_SHARE_LABEL","password":"DESIRED_SHARE_PASSWORD","path":"DIRECTORY_PATH"}' \
https://your.nextcloud.org/ocs/v2.php/apps/files_sharing/api/v1/shares
```
This link may have a default expiration date (set in "Sharing" admin settings) or you can set one in the previous request with the "expireDate" parameter (YYYY-MM-DD string). Set the date to next day. (If you'd set it to today, it would get locked right after midnight and become unusable for today).
This gives you back a JSON payload which contains the share ID in the ocs.data.id attribute and the share token in ocs.data.token.
### Change the share permission to "File drop" (4)
```text
curl -H "Authorization: Bearer USER_OAUTH_TOKEN" \
-H "ocs-apirequest: true" \
-H "content-type: application/json" \
-H "Accept: application/json" \
-X PUT \
-d '{"permissions":4}' \
https://your.nextcloud.org/ocs/v2.php/apps/files_sharing/api/v1/shares/SHARE_ID
```
### Upload to this shared directory
```text
curl -u SHARE_TOKEN:SHARE_PASSWORD \
-H "Accept: application/json" \
-X PUT \
-d @/path/to/file.txt \
https://your.nextcloud.org/public.php/webdav/TARGET_FILE_NAME
```
In you case, the file is uploaded by the browser but it's the same, you put the file content in the request body.
### Create shared access/link
```text
curl -H "Authorization: Bearer USER_OAUTH_TOKEN" \
-H "ocs-apirequest: true" \
-H "content-type: application/json" \
-H "Accept: application/json" \
-X POST \
-d '{"shareType":3,"label":"OPTIONAL_SHARE_LABEL","password":"DESIRED_SHARE_PASSWORD","path":"DIRECTORY_PATH"}' \
https://your.nextcloud.org/ocs/v2.php/apps/files_sharing/api/v1/shares
```
This link may have a default expiration date (set in "Sharing" admin settings) or you can set one in the previous request with the "expireDate" parameter (YYYY-MM-DD string). Set the date to next day. (If you'd set it to today, it would get locked right after midnight and become unusable for today).
This gives you back a JSON payload which contains the share ID in the ocs.data.id attribute and the share token in ocs.data.token.
### Change the share permission to "File drop" (4)
```text
curl -H "Authorization: Bearer USER_OAUTH_TOKEN" \
-H "ocs-apirequest: true" \
-H "content-type: application/json" \
-H "Accept: application/json" \
-X PUT \
-d '{"permissions":4}' \
https://your.nextcloud.org/ocs/v2.php/apps/files_sharing/api/v1/shares/SHARE_ID
```
### Upload to this shared directory
```text
curl -u SHARE_TOKEN:SHARE_PASSWORD \
-H "Accept: application/json" \
-X PUT \
-d @/path/to/file.txt \
https://your.nextcloud.org/public.php/webdav/TARGET_FILE_NAME
```
In you case, the file is uploaded by the browser but it's the same, you put the file content in the request body.