@@ -106,8 +106,11 @@ Checkout the example how to
106106
107107#### ` options.getFileIdFromRequest `
108108
109- Control how the Upload-ID is extracted from the request (` (req) => string | void ` ) By
110- default, it expects everything in the path after the last ` / ` to be the upload id.
109+ Control how the Upload-ID is extracted from the request
110+ (` (req, lastPath) => string | void ` )
111+
112+ By default, it expects everything in the path after the last ` / ` to be the upload id.
113+ ` lastPath ` is everything after the last ` / ` .
111114
112115Checkout the example how to
113116[ store files in custom nested directories] ( #example-store-files-in-custom-nested-directories ) .
@@ -157,7 +160,8 @@ This can be used to implement validation of upload metadata or add headers.
157160#### ` options.onUploadFinish `
158161
159162` onUploadFinish ` will be invoked after an upload is completed but before a response is
160- returned to the client (` (req, res, upload) => Promise<{ res: http.ServerResponse, status_code?: number, headers?: Record<string, string | number>, body?: string }> ` ).
163+ returned to the client
164+ (` (req, res, upload) => Promise<{ res: http.ServerResponse, status_code?: number, headers?: Record<string, string | number>, body?: string }> ` ).
161165
162166- You can optionally return ` status_code ` , ` headers ` and ` body ` to modify the response.
163167 Note that the tus specification does not allow sending response body nor status code
@@ -254,8 +258,9 @@ Called every [`postReceiveInterval`](#optionspostreceiveinterval) milliseconds f
254258upload while it‘s being written to the store.
255259
256260This means you are not guaranteed to get (all) events for an upload. For instance if
257- ` postReceiveInterval` is set to 1000ms and an PATCH request takes 500ms, no event is emitted.
258- If the PATCH request takes 2500ms, you would get the offset at 2000ms, but not at 2500ms.
261+ ` postReceiveInterval` is set to 1000ms and an PATCH request takes 500ms, no event is
262+ emitted. If the PATCH request takes 2500ms, you would get the offset at 2000ms, but not at
263+ 2500ms.
259264
260265Use ` POST_FINISH ` if you need to know when an upload is done.
261266
@@ -543,18 +548,13 @@ const server = new Server({
543548 id = Buffer .from (id, ' utf-8' ).toString (' base64url' )
544549 return ` ${ proto} ://${ host}${ path} /${ id} `
545550 },
546- getFileIdFromRequest (req ) {
547- const reExtractFileID = / ([^ /] + )\/ ? $ /
548- const match = reExtractFileID .exec (req .url as string)
549-
550- if (! match || path .includes (match[1 ])) {
551- return
552- }
553-
554- return Buffer .from (match[1 ], ' base64url' ).toString (' utf-8' )
551+ getFileIdFromRequest (req , lastPath ) {
552+ // lastPath is everything after the last `/`
553+ // If your custom URL is different, this might be undefined
554+ // and you need to extract the ID yourself
555+ return Buffer .from (lastPath, ' base64url' ).toString (' utf-8' )
555556 },
556557})
557-
558558` ` `
559559
560560### Example: use with Nginx
0 commit comments