GithubHelp home page GithubHelp logo

go-dropbox's Introduction

GoDoc Build Status

Dropbox

Simple Dropbox v2 client for Go.

For a higher level client take a look at go-dropy.

About

Modelled more or less 1:1 with the API for consistency and parity with the official documentation. More sugar should be implemented on top.

Testing

To manually run tests use the test account access token:

$ export DROPBOX_ACCESS_TOKEN=oENFkq_oIVAAAAAAAAAAC8gE3wIUFMEraPBL-D71Aq2C4zuh1l4oDn5FiWSdVVlL
$ go test -v

License

MIT

go-dropbox's People

Contributors

beyondblog avatar boki avatar kujenga avatar tj avatar ungerik avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar

go-dropbox's Issues

listing top level folders/files

Hey @tj , first of all this looks great and thank you for creating this.

So I have a folder/file structure like this:

/
/school/
/work/
/pictures/
/resume.pdf

I try using a path of "/" in my test program and I get a path/malformed_path/ response back. But if I use a folder a level down (ex: "/school") it works just fine.

So the question is how do I list the top-level stuff? I just checked out the Dropbox API itself and I didn't see anything. Any thoughts about how to handle this? Thanks!

Cannot upload file without ClientModified

Problem

Cannot upload file without ClientModified. Dropbox API return "500 Internal server error"

Reason 1. If type is time.Time, omitempty doesn't working

http://stackoverflow.com/questions/32643815/golang-json-omitempty-with-time-time-field

http://ideone.com/Uapadk

package main

import (
	"encoding/json"
	"fmt"
	"time"
)

type StringStruct struct {
	Val string `json:"val,omitempty"`
}

type IntStruct struct {
	Val int `json:"val,omitempty"`
}
type TimeStruct struct {
	Val time.Time `json:"val,omitempty"`
}

func main() {
	{
		a := &StringStruct{}
		b, _ := json.Marshal(a)
		fmt.Println(string(b))
	}
	{
		a := &IntStruct{}
		b, _ := json.Marshal(a)
		fmt.Println(string(b))
	}
	{
		a := &TimeStruct{}
		b, _ := json.Marshal(a)
		fmt.Println(string(b))
	}
}

output

{}
{}
{"val":"0001-01-01T00:00:00Z"}

Reason 2. "0001-01-01T00:00:00Z" is invalid date

client_modified : "0001-01-01T00:00:00Z"

$ curl -i -X POST https://content.dropboxapi.com/2/files/upload \
    --header "Authorization: Bearer <my-token>" \
    --header "Dropbox-API-Arg: {\"path\": \"/Homework/math/Matrices.txt\",\"mode\": \"add\",\"mute\": false, \"client_modified\":\"0001-01-01T00:00:00Z\"}" \
    --header "Content-Type: application/octet-stream" \
    --data-binary @local_file.txt
	
HTTP/1.1 500 Internal Server Error
Server: nginx
Date: Fri, 13 Jan 2017 16:20:38 GMT
Content-Type: text/plain; charset=utf-8
Transfer-Encoding: chunked
Connection: keep-alive
X-Dropbox-Request-Id: 0b2875fd8a0069a1791d5517d5c3f44f
X-Robots-Tag: noindex, nofollow, noimageindex

client_modified : "0001-01-01T00:00:00Z"

$ curl -i -X POST https://content.dropboxapi.com/2/files/upload \
    --header "Authorization: Bearer <my-token>" \
    --header "Dropbox-API-Arg: {\"path\": \"/Homework/math/Matrices.txt\",\"mode\": \"add\",\"mute\": false, \"client_modified\":\"2001-01-01T00:00:00Z\"}" \
    --header "Content-Type: application/octet-stream" \
    --data-binary @local_file.txt
	
HTTP/1.1 409 path/conflict/file/
Server: nginx
Date: Fri, 13 Jan 2017 16:21:14 GMT
Content-Type: application/json
Transfer-Encoding: chunked
Connection: keep-alive
X-Dropbox-Request-Id: fa466b7446442dfef16521036c59e089
X-Robots-Tag: noindex, nofollow, noimageindex

{"error_summary": "path/conflict/file/", "error": {".tag": "path", "reason": {".tag": "conflict", "conflict": {".tag": "file"}}, "upload_session_id": "AAAAAAAADm1RHB9OZkctbw"}}

Before 2017 Jan 04, if client_modified is "0001-01-01T00:00:00Z", it works.
After 2017 Jan 04, if client_modified is "0001-01-01T00:00:00Z", it return 500 internal server error.
Maybe dropbox modify their API.

Solution

A. use *time.Time

  • pros : simple
  • cons : interface will change. there are many time.Time + omitempty in library.

B. write custom marshal function

  • pros : trustable, can keep interface
  • cons : annoying task. there are many time.Time + omitempty in library.

C. Remove key and value if JSON value is "2001-01-01T00:00:00Z"

example

  1. Input string : {"path": "/Homework/math/Matrices.txt","mode": "add","mute": false, "client_modified":"2001-01-01T00:00:00Z"}
  2. If value is 2001-01-01T00:00:00Z, it is default value of time.Time
  3. Erase key and value from JSON
  4. Output string : {"path": "/Homework/math/Matrices.txt","mode": "add","mute": false}
  • pros : can keep interface
  • cons : some kinds of hack

Summary

I don't know which solution do you like. I can't make pull request. So I make issue.

add range header support for client.download

I am using your go-dropy and it is quite well with

io.Copy(os.Stdout, client.Open("/demo.txt"))

I write the data to the http.ResponseWriter , it work well , broswers can directly download the file ,
but it is a pity that the response is not rangeable

would you please modify the https://github.com/tj/go-dropbox/blob/master/client.go#L51 and add another parameters such as a map for addon http request header , so that the response can be rangeable .

It is very usefull sometimes , please

thank you very much !

Prime tests from code

instead of the stuff that is present on there already, at very least describe what fixtures are available, some for listing etc would be too slow to upload each time

Add error structs

their error responses are pretty awkward but it would be nice to have some types and struct(s)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.