Example #1
0
func main() {
	uf := upyun.NewUpYunForm(config.Bucket, config.Secret)

	options := map[string]string{
		"x-gmkerl-rotate": "90",
		"notify-url":      config.Notify,
	}
	fmt.Print(options)

	formResp, err := uf.Put("cc.jpg", "/{year}/{mon}/{day}/upload_{filename}{.suffix}", 3600, options)
	if err != nil {
		fmt.Println(err)
	} else {
		fmt.Printf("%+v\n", formResp)
	}
}
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
}