0

So I have multiple .sav files that I want to upload to my Dropbox I already created an app and have an access token

This is the code i have right now How can I make it upload all file with their name to my Dropbox

curl -X POST https://content.dropboxapi.com/2/files/alpha/upload \
  --header 'Authorization: Bearer <access-token>' \
  --header 'Content-Type: application/octet-stream' \
  --header 'Dropbox-API-Arg: {"path":"","mode":{".tag":"add"}}' \
  --data-binary @'test.sav'
1
  • no, unfortunately curl can only upload 1 file, if you need to upload 2 or more files, you must use something else. may i suggest libwww? Commented Oct 8, 2017 at 22:06

2 Answers 2

1

Just try this

#!/bin/bash

for file in ayam*.txt
do
 curl -X POST https://content.dropboxapi.com/2/files/upload \
--header "Authorization: Bearer <ACCESS_TOKEN>" \
--header "Dropbox-API-Arg: {\"path\": \"/${file}\"}" \
--header "Content-Type: application/octet-stream" \
--data-binary "@${file}"
done;

Sign up to request clarification or add additional context in comments.

Comments

0

Give a try to a loop:

$ for i in *.sav; do echo ${i}; done

If that works, it should print the names you will like to upload, then just replace echo ${i} with your curl command:

$ for i in *.sav; do \
curl -X POST https://content.dropboxapi.com/2/files/alpha/upload \
--header 'Authorization: Bearer <access-token>' \
--header 'Content-Type: application/octet-stream' \
--header 'Dropbox-API-Arg: {"path":"","mode":{".tag":"add"}}' \
--data-binary "@${i}"
done

2 Comments

It returns this as an error Error in call to API function "files/alpha/upload": HTTP header "Dropbox-API-Arg": could not decode input as JSONWarning: Couldn't read data from file "${i}\", this makes an empty POST.
I had a typo, give a try with --data-binary "@${i}"

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.