Skip to content

Commit

Permalink
fix: automatically create folder structure when uploading folder
Browse files Browse the repository at this point in the history
  • Loading branch information
flywukong committed Nov 20, 2023
1 parent bcbc5c9 commit 0357420
Showing 1 changed file with 7 additions and 4 deletions.
11 changes: 7 additions & 4 deletions cmd/cmd_object.go
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,6 @@ import (
"fmt"
"io"
"os"
"path"
"path/filepath"
"strings"
"time"
Expand Down Expand Up @@ -379,6 +378,11 @@ func uploadFolder(urlInfo string, ctx *cli.Context,
if !info.IsDir() {
fileInfos = append(fileInfos, info)
filePaths = append(filePaths, path)
} else {
fmt.Println("creating folder:", path)
if createFolderErr := uploadFile(bucketName, path+"/", path, urlInfo, ctx, gnfdClient, true, false, 0); createFolderErr != nil {
return toCmdErr(createFolderErr)
}
}
return nil
})
Expand All @@ -388,9 +392,8 @@ func uploadFolder(urlInfo string, ctx *cli.Context,
}
// upload folder
for id, info := range fileInfos {
objectName := path.Base(filePaths[id])
if uploadErr := uploadFile(bucketName, objectName, filePaths[id], urlInfo, ctx, gnfdClient, false, false, info.Size()); uploadErr != nil {
fmt.Printf("failed to upload object: %s, error:%v \n", objectName, uploadErr)
if uploadErr := uploadFile(bucketName, filePaths[id], filePaths[id], urlInfo, ctx, gnfdClient, false, false, info.Size()); uploadErr != nil {
fmt.Printf("failed to upload object: %s, error:%v \n", filePaths[id], uploadErr)
}
}

Expand Down

0 comments on commit 0357420

Please sign in to comment.