Example #1
0
func main() {
	ump := upyun.NewUpYunMultiPart(config.Bucket, config.Secret, 1024000)
	options := map[string]interface{}{
		"x-gmkerl-rotate": "90",
		"notify-url":      config.Notify,
		"ext-param":       "123456",
	}
	resp, err := ump.Put("cc.jpg", "/test/IMG-c"+fmt.Sprint(time.Now().Unix())+".jpg", 3600, options)
	fmt.Printf("%+v %v\n", resp, err)
}
Example #2
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

	fd, err := os.Open(file)
	if err != nil {
		return "", err
	}
	defer fd.Close()
	fi, err := fd.Stat()
	if err != nil {
		return "", err
	}
	fsize := fi.Size()

	if fsize < (2 << 27) {
		uf := upyun.NewUpYunForm(setting.Bucket, setting.Secret)
		if nil == uf {
			return "", errors.New("UpYun.NewUpYunForm Fail")
		}
		options := map[string]string{}

		_, err = uf.Put(file, key, 3600, options)

	} else {
		ump := upyun.NewUpYunMultiPart(setting.Bucket, setting.Secret, 1024000)
		if nil == ump {
			return "", errors.New("UpYun.NewUpYunForm Fail")
		}
		options := map[string]interface{}{}

		_, err = ump.Put(file, key, 3600, options)
	}
	if err != nil {
		return "", err
	}
	return url, nil
}