Пример #1
0
func main() {
	s := dropbox.Session{
		AppKey:     "APP_KEY",
		AppSecret:  "APP_SECRET",
		AccessType: "app_folder",
		Token: dropbox.AccessToken{
			Secret: "ACCESS_SECRET",
			Key:    "ACCESS_KEY",
		},
	}

	uriPath := dropbox.Uri{
		Root: dropbox.RootSandbox,
		Path: "NERDS/test_form.pdf",
	}

	// Upload a file
	if file, err := ioutil.ReadFile("./test_form.pdf"); err != nil {
		fmt.Println(err.Error())
	} else {
		m, err := dropbox.UploadFile(s, file, uriPath, nil)

		if err != nil {
			fmt.Println(err.Error())
		}
	}

	// Download the file
	if file, _, err := dropbox.GetFile(s, uriPath, nil); err == nil {
		ioutil.WriteFile("./test_result.pdf", file, os.ModePerm)
	} else {
		fmt.Println(err.Error())
	}
}
Пример #2
0
func GetFile(path string) (file []byte, err error) {
	uri := MakeURI(path)
	params := dropbox.Parameters{}
	res, _, err := dropbox.GetFile(Session, uri, &params)
	if err != nil {
		return nil, err
	}
	return res, err
}
Пример #3
0
// Download a file using dropbox
func DownloadFile(ds dropbox.Session, local string, remote string) (bool, error) {
	fname := path.Base(local)
	uriPath := getUri(fname, remote)

	f, _, err := dropbox.GetFile(ds, uriPath, nil)
	if err != nil {
		return false, err
	}
	err = ioutil.WriteFile(local, f, os.ModePerm)
	if err != nil {
		return false, err
	}

	return true, nil
}