Read custom pre-finish response header in Uppy

I am successfully using the pre-finish hook to set the correct Content Type on the uploaded file, and would like to return a success indicator to the client. I am able to set a response header value (X-Content-Type-Set: “True|False”), and can see it in the network tab as expected.

However, when I try to use onAfterResponse to header the header value:

      onAfterResponse: (req, res) => {

I get an error message from Chrome saying “Refused to get unsafe header”.

Is there any way for me to get this header value? Or is there any way for me to set information in the pre-finish hook that the client can receive? I would use ChangeFileInfo to add it to the metadata, but ChangeFileInfo is only relevant to the pre-upload hook.

The header is correctly included in the response, but the browser does not allow you to access it due to CORS (Cross-Origin Resource Sharing) limitations. You can read more about this mechanism on Cross-Origin Resource Sharing (CORS) - HTTP | MDN, but that gist is that you have to configure tusd, so that it can tell the browser that this header should be exposed to JavaScript. This can be done by adding following flag to tusd:

-cors-expose-headers X-Content-Type-Set
1 Like

Thanks! This worked perfectly

1 Like