Пример #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 setup() {
	fs.LoadConfig()
	fs.LoadSession()

	// Upload test file
	file, err := ioutil.ReadFile("./test_files/hello_world.txt")
	if err != nil {
		log.Fatalf("Setup Error: %v\n", err)
	}
	_, err = dropbox.UploadFile(fs.Session, file, uri, nil)
	if err != nil {
		log.Fatalf("Upload Error: %v\n", err)
	}
}
Пример #3
0
// Upload a file using dropbox connection
func UploadFile(ds dropbox.Session, local string, remote string) (bool, error) {
	fname := path.Base(local)
	uriPath := getUri(fname, remote)

	if file, err := ioutil.ReadFile(local); err != nil {
		return false, err
	} else {
		_, err := dropbox.UploadFile(ds, file, uriPath, nil)
		if err != nil {
			return false, err
		}
	}

	return true, nil
}
Пример #4
0
func dbUpload(s dropbox.Session, filename string) {
	uri := dropbox.Uri{
		Root: dropbox.RootDropbox,
		Path: filepath.Base(filename),
	}

	// Upload file
	if file, err := ioutil.ReadFile(filename); err != nil {
		log.Println(err)
	} else {
		_, err := dropbox.UploadFile(s, file, uri, nil)
		if err != nil {
			log.Println(err)
		} else {
			log.Println("Uploaded:", filename)
			err := os.Remove(filename)
			if err != nil {
				log.Println(err)
			}
		}
	}
}