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,
tusdotnetby default sends back a response status code as204 No Contentwhich means my response was being ignored from the library itself.I had to change the
HttpContext.Responsefrom theTusconfiguration to send status code as200 OKin order to pass the response back from theasp.net coreapplication. For exapmle in myOnFileCompleteAsyncevent I had to change default status code(204 No Content)to200 OK:In order to capture the response in the
onSuccesscallback:I had to modify the
javascriptlibrary in order to properlyemitthe response as the implementation of204 No Contentwas 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
_handleUploadResponsecallback:Similarly, needed to modify all the places it was being consumed.
CDN: https://cdn.jsdelivr.net/npm/tus-js-client@latest/dist/tus.js