seaweedfs/weed/operation/filer/register.go

36 lines
1,003 B
Go
Raw Normal View History

2016-07-21 08:23:56 +00:00
package filer
import (
"fmt"
"net/url"
"github.com/chrislusf/seaweedfs/weed/security"
"github.com/chrislusf/seaweedfs/weed/util"
2018-05-14 06:56:16 +00:00
"strconv"
)
type SubmitResult struct {
FileName string `json:"fileName,omitempty"`
FileUrl string `json:"fileUrl,omitempty"`
Fid string `json:"fid,omitempty"`
Size uint32 `json:"size,omitempty"`
Error string `json:"error,omitempty"`
}
2018-05-21 08:25:30 +00:00
func RegisterFile(filer string, path string, fileId string, fileSize int64, uid, gid int, secret security.Secret) error {
// TODO: jwt need to be used
_ = security.GenJwt(secret, fileId)
values := make(url.Values)
values.Add("path", path)
values.Add("fileId", fileId)
2018-05-14 06:56:16 +00:00
values.Add("fileSize", strconv.FormatInt(fileSize, 10))
2018-05-21 08:25:30 +00:00
values.Add("uid", strconv.Itoa(uid))
values.Add("gid", strconv.Itoa(gid))
_, err := util.Post("http://"+filer+"/admin/register", values)
if err != nil {
return fmt.Errorf("Failed to register path %s on filer %s to file id %s : %v", path, filer, fileId, err)
}
return nil
}