I am using tusdotnet
from tus.io
in ASP.NET Core Application, I am trying to send back a custom response as I am putting the entries in database and need to send back database Id
in the response. On the javascript side, after the file successfully gets uploaded, the response is always null.
onSuccess: function (response) {
try {
console.log(response); // this part is always null. even if the json response was received in the final network call.
} catch (e) {
console.log('Error onSuccess: ', e);
}
}
Need to get the response back.
https://github.com/tus/tus-js-client/blob/master/docs/api.md
Turns out,
tusdotnet
by default sends back a response status code as204 No Content
which means my response was being ignored from the library itself.I had to change the
HttpContext.Response
from theTus
configuration to send status code as200 OK
in order to pass the response back from theasp.net core
application. For exapmle in myOnFileCompleteAsync
event I had to change default status code(204 No Content)
to200 OK
:In order to capture the response in the
onSuccess
callback:I had to modify the
javascript
library in order to properlyemit
the response as the implementation of204 No Content
was modified to200 OK
. The function responsible for handling this change was_emitSuccess
:Had to modify the above method to:
After this change has been made, I had to modify all the places where this callback was being executed to pass through the response. Such as in
_handleUploadResponse
callback:Similarly, needed to modify all the places it was being consumed.
CDN: https://cdn.jsdelivr.net/npm/tus-js-client@latest/dist/tus.js