func main() { configFile, err := ioutil.ReadFile("config.json") if err != nil { panic("Error opening config file: " + err.Error()) } var c config err = json.Unmarshal(configFile, &c) if err != nil { panic(err) } var db *dropbox.Dropbox // 1. Create a new dropbox object. db = dropbox.NewDropbox() // 2. Provide your clientid and clientsecret (see prerequisite). db.SetAppInfo(c.Clientid, c.Clientsecret) // 3. Provide the user token. db.SetAccessToken(c.Token) fmt.Println(c.DropboxPath) err = db.DownloadToFile(c.DropboxPath, c.Destination, "") if err != nil { panic(err) } }
func handleOriginalFile(w http.ResponseWriter, r *http.Request) { var err error var db *dropbox.Dropbox // var input io.ReadCloser var length int64 var ok bool var cachedItem interface{} var s string if r.URL.Path[1:] == "favicon.ico" { return } cachedItem, ok = Lru.Get(r.URL.Path[5:]) if ok { item := cachedItem.(cacheItem) s = item.Value length = item.Length } else { var clientid, clientsecret string var token, rev string clientid = os.Getenv("CLIENTID") clientsecret = os.Getenv("CLIENTSECRET") token = os.Getenv("TOKEN") // 1. Create a new dropbox object. db = dropbox.NewDropbox() // 2. Provide your clientid and clientsecret (see prerequisite). db.SetAppInfo(clientid, clientsecret) // 3. Provide the user token. db.SetAccessToken(token) rev = "" //h := md5.New() //io.WriteString(h, r.URL.Path[5:]) //b := h.Sum(nil) str := strings.Replace(r.URL.Path[5:], "/", "-", -1) err = db.DownloadToFile("/"+r.URL.Path[5:], "/tmp/"+str, rev) if err != nil { fmt.Printf("123 Error: %s Url: %s Size: \n", err, r.URL.Path[5:], r.URL.Path[1:2]) } else { dat, err := ioutil.ReadFile("/tmp/" + str) if err != nil { } else { f, err := os.Open("/tmp/" + str) if err != nil { } fi, err := f.Stat() if err != nil { // Could not obtain stat, handle error } length = fi.Size() s = string(dat[:]) // w.Header().Set("Content-Length", strconv.FormatInt(fi.Size(), 10)) fmt.Fprintf(w, "%s", dat) Lru.Add(r.URL.Path[5:], cacheItem{Value: s, Length: length}) } } } w.Header().Set("Content-Length", strconv.FormatInt(length, 10)) fmt.Fprintf(w, "%s", s) }