Skip to content

Error parsing upload-id in v2.8.0 #1311

@ducpx

Description

@ducpx

Error parsing upload-id
Hi everyone, I'm trying to upgrade tusd v1 to v2. I added BasePath in v1

tusHandler, err := tusd.NewUnroutedHandler(tusd.Config{
		BasePath:                "/api/v1/upload",
		StoreComposer:           composer,
}

I tried to upload a new file, but I got an error

2025/08/27 15:03:16 INFO ResponseOutgoing method=PATCH path=/api/v1/upload/7c9d9878af20fc1b47a65b9e720b7926 requestId="" id=api/v1/upload/7c9d9878af20fc1b47a65b9e720b7926 status=404 body="ERR_UPLOAD_NOT_FOUND: upload not found\n"

I found that the issue is in the function

// extractIDFromPath extracts the upload ID from a path, which has already
// been stripped of the base path (done by the user). Effectively, we only
// remove leading and trailing slashes.
func extractIDFromPath(path string) (string, error) {
	return strings.Trim(path, "/"), nil
}

The function in v1 is

// extractIDFromPath pulls the last segment from the url provided
func extractIDFromPath(url string) (string, error) {
	result := reExtractFileID.FindStringSubmatch(url)
	if len(result) != 2 {
		return "", ErrNotFound
	}
	return result[1], nil
}

My http server is echo/v4

package main

import (
	"fmt"
	"net/http"

	handlers "github.com/ducpx/handlers"
	"github.com/labstack/echo/v4"
	"github.com/labstack/echo/v4/middleware"
)

func main() {
	tusApi := fmt.Sprint("", "/api/v1/upload/")
	fmt.Println(tusApi)

	bigFileUploadHandler := handlers.NewBigFileHandler("./data", tusApi)
	tusHandler := bigFileUploadHandler.TusConfig()

	tusHandlerPostFile := func(w http.ResponseWriter, r *http.Request) {
		tusHandler.PostFile(w, r)
	}
	tusHandlerHeadFile := func(w http.ResponseWriter, r *http.Request) {
		tusHandler.HeadFile(w, r)
	}
	tusHandlerPatchFile := func(w http.ResponseWriter, r *http.Request) {
		fmt.Println("Debug")
		tusHandler.PatchFile(w, r)
	}

	e := echo.New()
	e.HideBanner = true
	e.Use(middleware.Logger())
	api := e.Group("/api")
	api.POST("/v1/upload", echo.WrapHandler(http.HandlerFunc(tusHandlerPostFile)))
	api.HEAD("/v1/upload/:id", echo.WrapHandler(http.HandlerFunc(tusHandlerHeadFile)))
	api.PATCH("/v1/upload/:id", echo.WrapHandler(http.HandlerFunc(tusHandlerPatchFile)))

	err := e.Start(":8080")

	if err != nil && err != http.ErrServerClosed {
		e.Logger.Fatal(err)
	}
	e.Logger.Info("Server terminated")
}

Metadata

Metadata

Assignees

No one assigned

    Labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions