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.

39 lines
1.1 KiB

  1. package weed_server
  2. import (
  3. "bytes"
  4. "io/ioutil"
  5. "net/http"
  6. "strings"
  7. "github.com/chrislusf/seaweedfs/weed/glog"
  8. "github.com/chrislusf/seaweedfs/weed/storage"
  9. )
  10. func (fs *FilerServer) multipartUploadAnalyzer(w http.ResponseWriter, r *http.Request, replication, collection string) (fileId, urlLocation string, err error) {
  11. //Default handle way for http multipart
  12. if r.Method == "PUT" {
  13. buf, _ := ioutil.ReadAll(r.Body)
  14. r.Body = ioutil.NopCloser(bytes.NewBuffer(buf))
  15. fileName, _, _, _, _, _, _, _, pe := storage.ParseUpload(r)
  16. if pe != nil {
  17. glog.V(0).Infoln("failing to parse post body", pe.Error())
  18. writeJsonError(w, r, http.StatusInternalServerError, pe)
  19. err = pe
  20. return
  21. }
  22. //reconstruct http request body for following new request to volume server
  23. r.Body = ioutil.NopCloser(bytes.NewBuffer(buf))
  24. path := r.URL.Path
  25. if strings.HasSuffix(path, "/") {
  26. if fileName != "" {
  27. path += fileName
  28. }
  29. }
  30. fileId, urlLocation, err = fs.queryFileInfoByPath(w, r, path)
  31. } else {
  32. fileId, urlLocation, err = fs.assignNewFileInfo(w, r, replication, collection)
  33. }
  34. return
  35. }