tus/tus-node-server

UPLOAD create the file in Blob storage but Patch fails with Wrong url

SantoshAvaji opened this issue · 4 comments

Question
We are using node express server for our middleware service, also we use Tus server for uploading files.
We register tus server with our node server.

public async register(app: Express, apiPaths: string[]) {
    const tusServer = new tus.Server()
    // const fileNameFromUrl = (req) => {
    //   return req.url.replace(/\//g, "-");
    // };
    this.createStore()
    tusServer.datastore = this.datastore
    tusServer.handlers.POST = new AuthWrapperHandler(this.datastore, this.requestAuthenticator, tusServer.handlers.POST)

    const uploadApp = express()
    uploadApp.use(cors())
    uploadApp.all("*", tusServer.handle.bind(tusServer))
    // for (const path of apiPaths){
    //   app.use(`${path}/upload`, uploadApp)      
    // }

      app.use(`/upload`, uploadApp)      

    tusServer.on(tus.EVENTS.EVENT_FILE_CREATED, async (event) => {
      await this.onFileCreated(event)
    })

We host this service in Kubernites "service" type , service is reachable at "host/helpdesk/'
POST request will have correct endpoint path "host/helpdesk/upload", here file is created successfully in blob storage with 0 bytes data.
But for subsequent PATCH request , we are missing /helpdesk/ in the url , so we get 404 error for the url formatted.
final url looks like : " host/upload/tusfiles/fileid" , so we miss "helpdesk" in the url so we fail to upload the content
How to handle this case?

Setup details
Please provide following details, if applicable to your situation:

  • Operating System: Linux
  • Used tusd version: tusd -version
  • Used tusd data storage: azure Cloud Storage
  • Used tusd configuration: [what arguments are you using to invoke tusd?]
  • this.datastore = new ChunkedAzureBlobStore({
    path: /tusfiles,
    namingFunction: this.fingerprint,
    account: this.azureStorageAccountName,
    accountKey: this.azureStorageAccountKey,
    containerName: "tus",
    }, this.cacheProviderFactory)
  • Used tus client library: tus-js-client

You seem to be used tus-node-server, but this is the repository for tusd, a server written in Go. I will transfer the issue.

More to this issue:
Url for upload looks
https://{hostname}/helpdesk/upload
post request return 201 status ..
The above part works

But subsequent PATH request url look like below
https://{hostname}/upload/tusfiles/1fd46b39-0939-4312-bb1b-9119295f3e37
which returns 404 Not Found (from service worker)
The actual url should be
https://{hostname}/helpdesk/upload/tusfiles/1fd46b39-0939-4312-bb1b-9119295f3e37
But it always misses the helpdesk.
Please help me solve this issue

You seem to override the POST handler, maybe you don't send to correct Location header back yourself? That's what's used for the subsequent PATCH.

fenos commented

@SantoshAvaji i think you need to provide the path argument on the server for it to generate the correct url with the prefix /helpdesk/upload you are after.

I'm closing this issue for now, but feel free to post additional info if need further help. I'll be happy to re-open