Skip to content

Commit b60be97

Browse files
author
Athurg Feng
committed
上传文件时默认替换、修正相对路径设置的错误
1 parent a5621d9 commit b60be97

File tree

1 file changed

+4
-13
lines changed

1 file changed

+4
-13
lines changed

file.go

+4-13
Original file line numberDiff line numberDiff line change
@@ -8,18 +8,12 @@ import (
88
"mime/multipart"
99
"net/http"
1010
"net/url"
11-
"strings"
1211
)
1312

1413
//上传文件内容
1514
// fileContentMap的key是文件名,value是文件内容
1615
//当目标文件存在时,会自动重命名上传
17-
func (lib *Library) UploadFileContent(parentDir string, fileContentMap map[string][]byte) error {
18-
//参数检查
19-
if !strings.HasSuffix(parentDir, "/") {
20-
return fmt.Errorf("目录%s必须以/结尾", parentDir)
21-
}
22-
16+
func (lib *Library) UploadFileContent(dir string, fileContentMap map[string][]byte) error {
2317
body := &bytes.Buffer{}
2418
writer := multipart.NewWriter(body)
2519

@@ -33,12 +27,9 @@ func (lib *Library) UploadFileContent(parentDir string, fileContentMap map[strin
3327
}
3428

3529
//填充其他字段
36-
writer.WriteField("parent_dir", parentDir)
37-
38-
//FIXME:
39-
//文档中提到使用relative_path,系统会自动创建不存在的路径
40-
//但实际上好像没有效果,所以这里暂不支持这个参数
41-
//writer.WriteField("relative_path", subDir)
30+
writer.WriteField("replace", "1")
31+
writer.WriteField("parent_dir", "/")
32+
writer.WriteField("relative_path", dir)
4233

4334
err := writer.Close()
4435
if err != nil {

0 commit comments

Comments
 (0)