MCPcopy Create free account
hub / github.com/apecloud/myduckserver / UploadFile

Method UploadFile

storage/object_storage.go:33–56  ·  view source on GitHub ↗
(localDir, localFile, remotePath string)

Source from the content-addressed store, hash-verified

31}
32
33func (storageConfig *ObjectStorageConfig) UploadFile(localDir, localFile, remotePath string) (string, error) {
34 startMillis := time.Now().UnixMilli()
35 localFullPath := path.Join(localDir, localFile)
36 s3Cfg, err := storageConfig.buildConfig()
37 if err != nil {
38 return "", err
39 }
40
41 bucket, key := parseBucketAndPath(remotePath)
42 if strings.HasSuffix(key, "/") {
43 key += localFile
44 }
45
46 backupBucket := NewBucket(s3Cfg)
47
48 size, err := backupBucket.UploadFile(context.TODO(), bucket, key, localFullPath)
49 if err != nil {
50 return "", err
51 }
52
53 timeCost := time.Now().UnixMilli() - startMillis
54 return fmt.Sprintf("Uploaded %s (%d bytes) to %s://%s/%s in %d ms\n",
55 localFullPath, size, storageConfig.Provider, bucket, key, timeCost), nil
56}
57
58// DownloadFile downloads a file from the remote storage to the local storage.
59func (storageConfig *ObjectStorageConfig) DownloadFile(remotePath, localDir, localFile string) (string, error) {

Callers

nothing calls this directly

Calls 4

buildConfigMethod · 0.95
UploadFileMethod · 0.95
parseBucketAndPathFunction · 0.85
NewBucketFunction · 0.85

Tested by

no test coverage detected