Skip to content

Commit 462e5b6

Browse files
committed
fix: windows support for folder uploads (thanks Mark!)
1 parent 6144a4c commit 462e5b6

1 file changed

Lines changed: 13 additions & 1 deletion

File tree

internal/upload/uploads.go

Lines changed: 13 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,7 @@ import (
1515
"pinata/internal/config"
1616
cliConfig "pinata/internal/config"
1717
"pinata/internal/types"
18+
"runtime"
1819
"strings"
1920
"time"
2021

@@ -517,7 +518,18 @@ func createPinataMultipartRequest(filePath string, files []string, body io.Write
517518
part, err = writer.CreateFormFile("file", filepath.Base(f))
518519
} else {
519520
relPath, _ := filepath.Rel(filePath, f)
520-
part, err = writer.CreateFormFile("file", filepath.Join(stats.Name(), relPath))
521+
if runtime.GOOS == "windows" {
522+
relPathForward := strings.ReplaceAll(relPath, "\\", "/")
523+
folderName := stats.Name()
524+
folderNameForward := strings.ReplaceAll(folderName, "\\", "/")
525+
fullPath := folderNameForward
526+
if relPathForward != "" {
527+
fullPath = folderNameForward + "/" + relPathForward
528+
}
529+
part, err = writer.CreateFormFile("file", fullPath)
530+
} else {
531+
part, err = writer.CreateFormFile("file", filepath.Join(stats.Name(), relPath))
532+
}
521533
}
522534
if err != nil {
523535
return contentType, err

0 commit comments

Comments
 (0)