Beispiel #1
0
func (s RSService) UploadEx(upToken string, localFile, entryURI string, mimeType, customMeta, callbackParam string,
	crc int64, rotate int) (ret PutRet, code int, err error) {

	action := "/rs-put/" + httputil.EncodeURI(entryURI)
	if mimeType == "" {
		mimeType = "application/octet-stream"
	}
	action += "/mimeType/" + httputil.EncodeURI(mimeType)
	if customMeta != "" {
		action += "/meta/" + httputil.EncodeURI(customMeta)
	}
	if crc >= 0 {
		action += "/crc32/" + strconv.FormatInt(crc, 10)
	}
	if rotate >= 0 {
		action += "/rotate/" + strconv.FormatInt(int64(rotate), 10)
	}
	//url := "http://up.qbox.me" + "/upload"
	//url := "http://m1.qbox.me" + "/upload"
	//url := "http://m1.qbox.me" + "/upload"
	url := s.Config.HostIp["up_ip"] + "/upload"

	fmt.Println()
	multiParams := map[string][]string{
		"action": {action},
		"file":   {"@" + localFile},
		"auth":   {upToken},
	}
	if callbackParam != "" {
		multiParams["params"] = []string{callbackParam}
	}

	code, err = s.Conn.CallWithMultipart(&ret, url, multiParams)
	return
}
Beispiel #2
0
Datei: up.go Projekt: shtlee/qa
func (r Service) Mkfile(
	ret interface{}, cmd, entry string,
	fsize int64, params, callbackParams string, checksums []string) (code int, err error) {
	if callbackParams != "" {
		params += "/params/" + httputil.EncodeURI(callbackParams)
	}

	n := len(checksums)
	body := make([]byte, 20*n)
	for i, checksum := range checksums {
		ret, err2 := base64.URLEncoding.DecodeString(checksum)
		if err2 != nil {
			code, err = 400, errors.New("mkfile error")
			return
		}
		copy(body[i*20:], ret)
	}
	code, err = r.Conn.CallWithEx(
		ret, r.ip+cmd+httputil.EncodeURI(entry)+"/fsize/"+strconv.FormatInt(fsize, 10)+params,
		r.host, "application/octet-stream", bytes.NewReader(body), (int64)(len(body)))
	return
}