You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

38 lines
1014 B

  1. package weed_server
  2. import (
  3. "net/http"
  4. "github.com/chrislusf/seaweedfs/weed/glog"
  5. "github.com/chrislusf/seaweedfs/weed/filer2"
  6. "strconv"
  7. "github.com/chrislusf/seaweedfs/weed/pb/filer_pb"
  8. )
  9. func (fs *FilerServer) registerHandler(w http.ResponseWriter, r *http.Request) {
  10. path := r.FormValue("path")
  11. fileId := r.FormValue("fileId")
  12. fileSize, err := strconv.ParseUint(r.FormValue("fileSize"), 10, 64)
  13. if err != nil {
  14. glog.V(4).Infof("register %s to %s parse fileSize %s: %v", fileId, path, r.FormValue("fileSize"), err)
  15. writeJsonError(w, r, http.StatusInternalServerError, err)
  16. return
  17. }
  18. entry := &filer2.Entry{
  19. FullPath: filer2.FullPath(path),
  20. Attr: filer2.Attr{
  21. Mode: 0660,
  22. },
  23. Chunks: []*filer_pb.FileChunk{{
  24. FileId: fileId,
  25. Size: fileSize,
  26. }},
  27. }
  28. err = fs.filer.CreateEntry(entry)
  29. if err != nil {
  30. glog.V(4).Infof("register %s to %s error: %v", fileId, path, err)
  31. writeJsonError(w, r, http.StatusInternalServerError, err)
  32. } else {
  33. w.WriteHeader(http.StatusOK)
  34. }
  35. }