Dropbox API Support & Feedback
Find help with the Dropbox API from other developers.
Hi,
I was able to upload a file using golang using this:
I'm manually downloading. So, its definitely in the uploading process. I will look into this further. Thanks for the help
The content of the uploaded file should not be part of a multipart request.
An example:
package main
import (
"net/http"
"strings"
"fmt"
"io"
)
var client = &http.Client{}
func Upload(body io.Reader, filepath string) (string, error){
req, err := http.NewRequest("POST", "https://content.dropboxapi.com/2/files/upload", body)
if err != nil{
return "Could not create new requests", err
}
dbx_args := fmt.Sprintf("{\"autorename\":true,\"mode\":\"overwrite\",\"mute\":true,\"path\":\"%s\",\"strict_conflict\":false}", filepath)
req.Header = map[string][]string{
"Authorization":{"Bearer <YOUr-TOKEN-HERE>"},
"Content-Type": {"application/octet-stream"},
"Dropbox-API-Arg" : {dbx_args},
}
res, err := client.Do(req)
if err != nil{
return "Failure to connect", err
}
status_code := res.StatusCode
if status_code != 200{
return "Upload failed", fmt.Errorf("%d", status_code)
}
return "OK",nil
}
func main(){
file_content := strings.NewReader("Some file content")
filepath := "/Folder/test_file.txt"
msg, err := Upload(file_content, filepath)
if err != nil{
fmt.Println(err)
} else{
fmt.Println(msg)
}
}
The way we work is changing. Share and discover new ways to work smarter with Dropbox in our community.
Sound good? Let's get started.Hi there!
If you need more help you can view your support options (expected response time for a ticket is 24 hours), or contact us on Twitter or Facebook.
For more info on available support options, see this article.
If you found the answer to your question, please 'like' the post to say thanks to the user!