I'm trying to download files from Huawei, more precisely from their cloud storage. The issue is, I have been unable to connect to it.
I found an SDK from Huawei, but I'm a little lost on all the protocol I can use to connect to it, and I haven't been able to make one working, each time. And the documentations are not very helpful.
I also found this. There is an example of downloading a file. Here, I can't even connect to Huawei. In the AppGalery, project settings, I downloaded the configuration file and tried the endpoint, but without success.
Here is what I tried with obs (I know/guess it should be agc, but I haven't found a package for it), but not working due to the host.
/**
* 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()
}
Thank you for your help
May you try the official OBS SDK?
OBS SDK for GO
https://support.huaweicloud.com/intl/en-us/sdk-go-devg-obs/obs_33_0001.html
Different types of download:
https://support.huaweicloud.com/intl/en-us/sdk-go-devg-obs/obs_23_0501.html
Normal download + Code:
https://support.huaweicloud.com/intl/en-us/sdk-go-devg-obs/obs_23_0502.html