Beispiel #1
0
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
}
Beispiel #2
0
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

}