GithubHelp home page GithubHelp logo

ufilesdk-dev / ufile-gosdk Goto Github PK

View Code? Open in Web Editor NEW
34.0 34.0 27.0 235 KB

UCloud 对象存储官方 SDK

Home Page: https://www.ucloud.cn/

License: Apache License 2.0

Go 100.00%
golang library object-storage ucloud-sdk

ufile-gosdk's People

Contributors

chenwbyx avatar delexxie avatar joydchh avatar kuixiao avatar leyafo avatar luxiaobai avatar myml avatar ufo2243 avatar zhijian-pro avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

ufile-gosdk's Issues

文件下载时返回token expires错误

hi ,你好!

  1. 使用GetPublicURL并调用函数Download时,服务端返回错误: { "RetCode": -148643, "ErrMsg": "no authorization found" }
  2. 使用GetPrivateURL并调用函数Download时,服务端返回错误: { "RetCode": -148660, "ErrMsg": "token expires" }
    函数调用的http接口:https://docs.ucloud.cn/api/ufile-api/get_file
    请问,应该怎么排查这个问题?
    另外,bucket是私有的。
    谢谢!

License?

Hi,

Can you add a license to your project? Or let me know what the license is if I have missed that info somewhere.

Thank you,
Ariel

文件下载

在file.go中,只有一个Download函数,该函数只是发起一个http请求,请提供能将baody数据直接存放到文件中的函数,比如:Download(localFileName, fileKey string)

[bug]customized headers cannot be passed to the http request by sdk

I created an UFileRequest with:

	header = http.Header{
		"Range": []string{fmt.Sprintf("bytes=%d-%d", 0, 25)},
	}
        req = helper.NewFileRequest(BucketName, header)

But when I called:

        err = req.DownloadFile(io.Discard, fileName)

I found that the header wasn't in the underlying http request.

key以/开始

问题描述:
调用函数DownloadFile下载文件时,运行到行 err := u.HeadFile(keyName) 出错。错误内容:Remote response code is 403 - Forbidden not 2xx call DumpResponse(true) show details%!(EXTRA string=HTTP/1.1 403
X-Sessionid: 95f34139-862d-4c4f-a8ac-1bb0af6c675fServer: nginx/1.11.1Date: Tue, 30 Oct 2018 11:22:42 GMTContent-Type: application/jsonContent-Length: 53Connection: keep-aliveVary: Origin)
传入的参数:keyName= “/data/a/b/c.txt”
试图解决:
运行demo_downloadfile.go,如果使用默认文件名称,完全正确。如果将文件名称替换为:"/data/a/b/c.txt",在运行到PutFile函数时,报错:HTTP/1.1 403
Content-Type: application/jsonContent-Length: 53Connection: keep-aliveX-Sessionid: d7ce59c2-80bd-45d9-93d8-45408a8aadb3Server: nginx/1.11.1Date: Tue, 30 Oct 2018 11:27:07 GMT{ "RetCode": -148658, "ErrMsg": "invalid signature" }
初步判定原因:keyName以'/'开始,服务端验证签名失败。
疑问:为什么以'/'开始,导致403?请针对这种情况修正一下代码。

license

Would you like to add a license for your project?

invalid signature

请问各个接口是否已经测试过,我这里出现以下问题。
调用file.go中接口PrefixFileList出现403错误,具体错误:{ "RetCode": -148658, "ErrMsg": "invalid signature" }。
但是,使用同样的公私钥配置,利用“管理工具filemgr-linux64”可以获取到文件列表。
请看看是不是生成signature的方式有问题。谢谢!

分片上传不支持直接从 body 上传到对象存储

业务场景:
前端 ----> 上传文件 -----> 应用服务 -------> 对象存储

目前 sdk,貌似只支持本地文件上传,即是应用服务需要自己实现一次文件上传保存到本地,再上传到对象存储.
不支持应用服务做中转这样的吗,即应用服务不用把文件存放在本地.

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

相关代码如下:

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 需要更新

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.