(localDir, localFile, remotePath string)
| 31 | } |
| 32 | |
| 33 | func (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. |
| 59 | func (storageConfig *ObjectStorageConfig) DownloadFile(remotePath, localDir, localFile string) (string, error) { |
nothing calls this directly
no test coverage detected