示例#1
0
文件: main.go 项目: ckagiri/YNAWB
/* Retrieves files from the users Dropbox. Returns a byte
 * array of the files contents. */
func loadDropboxFile(path string, db *dropbox.Dropbox) ([]byte, error) {

	closer, _, err := db.Download(path, "", 0)

	if err != nil {

		fmt.Printf("Error loading dropbox file: %v\n", err)
		return nil, err

	}

	file, err := ioutil.ReadAll(closer)

	return file, err

}
示例#2
0
func ReadFile(config *DropboxConfig, file string) (string, error) {

	var err error
	var db *dropbox.Dropbox
	var s string

	db = dropbox.NewDropbox()
	db.SetAppInfo(config.AppKey, config.AppSecret)
	db.SetAccessToken(config.Token)

	rd, _, err := db.Download(file, "", 0)
	if err != nil {
		return s, err
	}

	buf := new(bytes.Buffer)
	buf.ReadFrom(rd)
	s = buf.String()

	return s, nil
}