|
|
@ -55,23 +55,24 @@ func UploadData(uploadUrl string, filename string, cipher bool, data []byte, isI |
|
|
|
} |
|
|
|
|
|
|
|
// Upload sends a POST request to a volume server to upload the content with fast compression
|
|
|
|
func Upload(uploadUrl string, filename string, cipher bool, reader io.Reader, isInputGzipped bool, mtype string, pairMap map[string]string, jwt security.EncodedJwt) (uploadResult *UploadResult, err error) { |
|
|
|
func Upload(uploadUrl string, filename string, cipher bool, reader io.Reader, isInputGzipped bool, mtype string, pairMap map[string]string, jwt security.EncodedJwt) (uploadResult *UploadResult, err error, data []byte) { |
|
|
|
hash := md5.New() |
|
|
|
reader = io.TeeReader(reader, hash) |
|
|
|
uploadResult, err = doUpload(uploadUrl, filename, cipher, reader, isInputGzipped, mtype, pairMap, jwt) |
|
|
|
uploadResult, err, data = doUpload(uploadUrl, filename, cipher, reader, isInputGzipped, mtype, pairMap, jwt) |
|
|
|
if uploadResult != nil { |
|
|
|
uploadResult.Md5 = fmt.Sprintf("%x", hash.Sum(nil)) |
|
|
|
} |
|
|
|
return |
|
|
|
} |
|
|
|
|
|
|
|
func doUpload(uploadUrl string, filename string, cipher bool, reader io.Reader, isInputGzipped bool, mtype string, pairMap map[string]string, jwt security.EncodedJwt) (uploadResult *UploadResult, err error) { |
|
|
|
data, readErr := ioutil.ReadAll(reader) |
|
|
|
if readErr != nil { |
|
|
|
err = fmt.Errorf("read input: %v", readErr) |
|
|
|
func doUpload(uploadUrl string, filename string, cipher bool, reader io.Reader, isInputGzipped bool, mtype string, pairMap map[string]string, jwt security.EncodedJwt) (uploadResult *UploadResult, err error, data []byte) { |
|
|
|
data, err = ioutil.ReadAll(reader) |
|
|
|
if err != nil { |
|
|
|
err = fmt.Errorf("read input: %v", err) |
|
|
|
return |
|
|
|
} |
|
|
|
return doUploadData(uploadUrl, filename, cipher, data, isInputGzipped, mtype, pairMap, jwt) |
|
|
|
uploadResult, uploadErr := doUploadData(uploadUrl, filename, cipher, data, isInputGzipped, mtype, pairMap, jwt) |
|
|
|
return uploadResult, uploadErr, data |
|
|
|
} |
|
|
|
|
|
|
|
func doUploadData(uploadUrl string, filename string, cipher bool, data []byte, isInputGzipped bool, mtype string, pairMap map[string]string, jwt security.EncodedJwt) (uploadResult *UploadResult, err error) { |
|
|
|