MCPcopy Create free account
hub / github.com/tus/tusd / PostFileV2

Method PostFileV2

pkg/handler/unrouted_handler.go:468–633  ·  view source on GitHub ↗

PostFile creates a new file upload using the datastore after validating the length and parsing the metadata.

(w http.ResponseWriter, r *http.Request)

Source from the content-addressed store, hash-verified

466// PostFile creates a new file upload using the datastore after validating the
467// length and parsing the metadata.
468func (handler *UnroutedHandler) PostFileV2(w http.ResponseWriter, r *http.Request) {
469 currentUploadDraftInteropVersion := getIETFDraftInteropVersion(r)
470 c := handler.getContext(w, r)
471
472 // Parse headers
473 contentType := r.Header.Get("Content-Type")
474 contentDisposition := r.Header.Get("Content-Disposition")
475 willCompleteUpload := isIETFDraftUploadComplete(r)
476
477 info := FileInfo{
478 MetaData: make(MetaData),
479 }
480
481 size, sizeIsDeferred, err := getIETFDraftUploadLength(r)
482 if err != nil {
483 handler.sendError(c, err)
484 return
485 }
486
487 if !sizeIsDeferred {
488 info.Size = size
489 } else {
490 // Error out if the storage does not support upload length deferring, but we need it.
491 if !handler.composer.UsesLengthDeferrer {
492 handler.sendError(c, ErrNotImplemented)
493 return
494 }
495
496 info.SizeIsDeferred = true
497 }
498
499 // Parse Content-Type and Content-Disposition to get file type or file name
500 if contentType != "" {
501 fileType, _, err := mime.ParseMediaType(contentType)
502 if err != nil {
503 handler.sendError(c, err)
504 return
505 }
506
507 info.MetaData["filetype"] = fileType
508 }
509
510 if contentDisposition != "" {
511 _, values, err := mime.ParseMediaType(contentDisposition)
512 if err != nil {
513 handler.sendError(c, err)
514 return
515 }
516
517 if values["filename"] != "" {
518 info.MetaData["filename"] = values["filename"]
519 }
520 }
521
522 resp := HTTPResponse{
523 StatusCode: http.StatusCreated,
524 Header: HTTPHeader{},
525 }

Callers 1

PostFileMethod · 0.95

Calls 15

getContextMethod · 0.95
sendErrorMethod · 0.95
MergeWithMethod · 0.95
GetInfoMethod · 0.95
absFileURLMethod · 0.95
lockUploadMethod · 0.95
writeChunkMethod · 0.95
sendRespMethod · 0.95

Tested by

no test coverage detected