ufile-gosdk icon indicating copy to clipboard operation
ufile-gosdk copied to clipboard

DownloadFile error strconv.ParseInt: parsing "": invalid syntax

Open lixd opened this issue 4 years ago • 1 comments

相关代码如下:

func (u *UFileRequest) DownloadFile(writer io.Writer, keyName string) error {

	reqURL := u.GetPrivateURL(keyName, 24*time.Hour)
	req, err := http.NewRequest("GET", reqURL, nil)
	if err != nil {
		return err
	}

	resp, err := u.requestWithResp(req)
	if err != nil {
		return err
	}
	defer resp.Body.Close()

	u.LastResponseStatus = resp.StatusCode
	u.LastResponseHeader = resp.Header
	u.LastResponseBody = nil //流式下载无body存储在u里
	u.lastResponse = resp
	if !VerifyHTTPCode(resp.StatusCode) {
		return fmt.Errorf("Remote response code is %d - %s not 2xx call DumpResponse(true) show details",
			resp.StatusCode, http.StatusText(resp.StatusCode))
	}
	size := u.LastResponseHeader.Get("Content-Length")
	fileSize, err := strconv.ParseInt(size, 10, 0)
	if err != nil || fileSize < 0 {
		return fmt.Errorf("Parse content-lengt returned error")
	}
	_, err = io.Copy(writer, resp.Body)
	return err
}

由于size := u.LastResponseHeader.Get("Content-Length") 获取不到 length 导致后续 _, err = io.Copy(writer, resp.Body) 没执行,下载文件失败。 请确认是新版API不返回 Length 属性了?还是 SDK 需要更新

lixd avatar Jun 10 '21 04:06 lixd

Hi, is there any follow up on this issue now? I've had a lot of questions lately too, but I've noticed that they don't seem to be dealing with these issues.

abyss-w avatar Aug 31 '21 06:08 abyss-w