由于几天,我试图从华为下载文件,更准确地说是在他们的云存储.问题是,我还没有能够连接到它...我发现了一个来自华为的SDK:https://github.com/huaweicloud/huaweicloud-sdk-go-v3但是我对所有可以用来连接到它的协议都有点迷失,而且我每次都不能让一个工作。老实说,文档并没有真正帮助我。
我还发现了这个:https://github.com/huaweicloud/huaweicloud-sdk-go-obs有一个下载文件的例子,在这里,我连华为都连接不上...在AppGalery,项目设置中,我下载了配置文件,尝试了端点,但没有成功...
这是我尝试与obs(我知道/猜它应该是agc,但我还没有找到一个包),但不工作,由于主机...
/**
* This sample demonstrates how to download an object
* from OBS in different ways using the OBS SDK for Go.
*/
package huawei
import (
"fmt"
"io"
"github.com/huaweicloud/huaweicloud-sdk-go-obs/obs"
)
type DownloadSample struct {
bucketName string
objectKey string
location string
obsClient *obs.ObsClient
}
func newDownloadSample(ak, sk, endpoint, bucketName, objectKey, location string) *DownloadSample {
obsClient, err := obs.New(ak, sk, endpoint)
if err != nil {
panic(err)
}
return &DownloadSample{obsClient: obsClient, bucketName: bucketName, objectKey: objectKey, location: location}
}
func (sample DownloadSample) GetObject() {
input := &obs.GetObjectInput{}
input.Bucket = sample.bucketName
input.Key = sample.objectKey
fmt.Printf("%+v\n", input)
output, err := sample.obsClient.GetObject(input)
if err != nil {
panic(err)
}
defer func() {
errMsg := output.Body.Close()
if errMsg != nil {
panic(errMsg)
}
}()
fmt.Println("Object content:")
body, err := io.ReadAll(output.Body)
if err != nil {
panic(err)
}
fmt.Println(string(body))
fmt.Println()
}
func RunDownloadSample() {
const (
endpoint = "theEndPointInConfigJSONFile"
ak = "prettySureOfThis"
sk = "prettySureOfThis"
bucketName = "prettySureOfThis"
objectKey = "test.txt" // a txt in the bucket to try to download it
location = ""
)
sample := newDownloadSample(ak, sk, endpoint, bucketName, objectKey, location)
fmt.Println("Download object to string")
sample.GetObject()
}
谢谢你的帮忙
1条答案
按热度按时间mwkjh3gx1#
可以试试官方的OBS SDK吗?
GO OBS SDK
https://support.huaweicloud.com/intl/en-us/sdk-go-devg-obs/obs_33_0001.html
不同下载类型:
https://support.huaweicloud.com/intl/en-us/sdk-go-devg-obs/obs_23_0501.html
正常下载+编码:
https://support.huaweicloud.com/intl/en-us/sdk-go-devg-obs/obs_23_0502.html