func main() { up := upyun.NewUpYun(config.Bucket, config.Username, config.Passwd) headers := map[string]string{ "x-gmkerl-watermark-type": "text", "x-gmkerl-watermark-font": "simhei", "x-gmkerl-watermark-color": "#faf1fb", "x-gmkerl-watermark-size": "20", "x-gmkerl-watermark-text": "UPYUN", "x-gmkerl-watermark-border": "#40404085", "x-gmkerl-watermark-margin": "10,10", } fd, _ := os.Open("cc.jpg") x := fmt.Sprintf("/wm/cc%d.jpg", time.Now().Unix()%10000) fmt.Println(up.Put(x, fd, false, headers)) c := up.GetLargeList("/", true) for { v, more := <-c if !more { break } fmt.Println(v) } }
func upyunsave(file string) (url string, err error) { var key string for _, key = range strings.Split(file, "/") { } opath := "/" + setting.Bucket + "/" + key url = "http://" + setting.Endpoint + opath var u *upyun.UpYun u = upyun.NewUpYun(setting.Bucket, setting.User, setting.Passwd) if nil == u { return "", errors.New("UpYun.NewUpYun Fail") } u.SetEndpoint(setting.Endpoint) fin, err := os.Open(file) if err != nil { return "", err } defer fin.Close() _, err = u.Put(key, fin, false, "") if err != nil { return "", err } return url, nil }
func NewFsDriver(bucket, username, password, curDir string, conc int, logger *log.Logger) (*FsDriver, error) { driver := &FsDriver{ curDir: curDir, operator: username, bucket: bucket, up: upyun.NewUpYun(bucket, username, password), maxConc: conc, logger: logger, } var err error _, err = driver.up.Usage() if err != nil { return nil, err } driver.progress = uiprogress.New() driver.progress.RefreshInterval = time.Millisecond * 100 driver.progress.Start() return driver, nil }
func upcloudsave(file string) (url string, err error) { var key string //get the filename from the file , eg,get "1.txt" from "/home/liugenping/1.txt" for _, key = range strings.Split(file, "/") { } opath := "/" + g_upBucket + "/" + key url = "http://" + g_upEndpoint + opath var u *upyun.UpYun u = upyun.NewUpYun(g_upBucket, g_upUser, g_upPasswd) if nil == u { return "", errors.New("UpYun.NewUpYun Fail") } /* Endpoint list: Auto = "v0.api.upyun.com" Telecom = "v1.api.upyun.com" Cnc = "v2.api.upyun.com" Ctt = "v3.api.upyun.com" */ u.SetEndpoint(g_upEndpoint) fin, err := os.Open(file) if err != nil { return "", err } defer fin.Close() _, err = u.Put(key, fin, false, "") if err != nil { return "", err } return url, nil }