oracle / oci-go-sdk

Go SDK for Oracle Cloud Infrastructure
https://cloud.oracle.com/cloud-infrastructure
Other
176 stars 82 forks source link

`UploadRequest` creates `ObjectStorageClient` when uploading request is processing. #441

Open urunimi opened 1 year ago

urunimi commented 1 year ago

I don't think it is good idea to create ObjectStorageClient instance while uploading.

How about return error instantly if the client is not set?

I used long time to debug this issue and I can create a pull request.

https://github.com/oracle/oci-go-sdk/blob/a172b320b82f9d45afe9a044511d4eba550d06d1/objectstorage/transfer/upload_manager_req_resp.go#L144-L157

func New() (CloudStorage, error) {
    // I used `ConfigurationProviderEnvironmentVariables` to create the configuration.
    conf := common.ConfigurationProviderEnvironmentVariables("oci", "")
    // It passes `IsConfigurationProviderValid`. 
    c, err := objectstorage.NewObjectStorageClientWithConfigurationProvider(conf)
    // ...
}

func (s *ociObjectStorage) Upload(objectName string, data []byte) error {
    // ...
    uploadManager := transfer.NewUploadManager()

    req := transfer.UploadStreamRequest{
        UploadRequest: transfer.UploadRequest{
            NamespaceName:                       &namespace,
            BucketName:                          &bname,
            ObjectName:                          &objectName,
            EnableMultipartChecksumVerification: common.Bool(true),
        },
        // ...
    }

    // I got a client error if `ObjectStorageClient` is set manually.
    _, err := uploadManager.UploadStream(ctx, req)
    // ...
}
KartikShrikantHegde commented 1 year ago

@urunimi assigning this issue to the Object Storage team to take a look and suggest.