tus / tusd

Reference server implementation in Go of tus: the open protocol for resumable file uploads
https://tus.github.io/tusd
MIT License
2.92k stars 465 forks source link

pre-finish blocking script problem #1132

Closed jaejungkim closed 1 week ago

jaejungkim commented 1 month ago

Question

./tusd --port 9191 --hooks-dir=./hooks_dir/ --hooks-enabled-events="pre-finish,post-finish" I'm running tusd 2.4.0 like this and hooks_dir/pre-finish Python scripts are shown below

 #!/usr/bin/env python
      2 # -*- encoding: utf-8 -*-
      3 import os
      4 import json
      5 import sys
      6
      7 #
      8 results = os.environ.items()
      9
     10 json_result = json.dumps(dict(results))
     11
     12 print(json_result)
     13
     14 with open("json_results_env_pre_finish.txt","w") as f:
     15     f.write(json_result)
     16 print("error pre  pre-finish")
     17 sys.exit(1)
     18 print("error post pre-finish")

However, when uploading a tusd file from the uppy react dashboard, it is blocked on the client in pre-create, but I know that pre-finish is a blocking code, but the server throws a 500 server error and there is no error message in the client? Is this the expected behavior? How do I get an error in the uppy dashboard when sys.exit(1) is used in pre-finish, as in pre-create? Is it possible?

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

Acconut commented 1 month ago

the server throws a 500 server error and there is no error message in the client? Is this the expected behavior?

Yes, this is expected. Your hooks are exiting with a non-zero exit code, which is understood as a failure in its execution. If you want to show an error message to the client, you have to exit with the exit code 0, but write a properly formatted hook response to stdout. Please read through https://tus.github.io/tusd/advanced-topics/hooks/#file-hooks (the specific for the file hooks but also the entire hook process in general) to learn more.