You might see that the Dropbox Community team have been busy working on some major updates to the Community itself! So, here is some info on what’s changed, what’s staying the same and what you can expect from the Dropbox Community overall.
Forum Discussion
fenario
7 years agoExplorer | Level 3
golang file upload
Hi, I was able to upload a file using golang using this: var ( body = &bytes.Buffer{} writer = multipart.NewWriter(body) ) b := dropboxAPI{ ...
DV2811
3 years agoNew member | Level 2
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)
}
}
About Dropbox API Support & Feedback
Find help with the Dropbox API from other developers.
5,915 PostsLatest Activity: 6 years agoIf you need more help you can view your support options (expected response time for an email or ticket is 24 hours), or contact us on X or Facebook.
For more info on available support options for your Dropbox plan, see this article.
If you found the answer to your question in this Community thread, please 'like' the post to say thanks and to let us know it was useful!