react-activestorage-provider
react-activestorage-provider copied to clipboard
File upload erroring with modified ActiveStorage::BaseController
I updated my ActiveStorage::BaseController on my Rails API to require authentication details specific to our implementation. This seems to work fine for GET requests for an uploaded file, as well as for the Blob being POSTed during the upload, but then there seems to be a PUT request, which I assume is the actual file being uploaded, which fails because it doesn't have the custom header I provided to DirectUploadProvider.
While I still believe that the headers prop should provide the storage request with the same headers, I seemingly fixed this issue by passing the onBeforeStorageRequest prop and modifying the request like this:
onBeforeStorageRequest={({ id, file, xhr }) => {
xhr.setRequestHeader('APIKey', /* My API Key */);
xhr.setRequestHeader('UserToken', /* My User Token */);
}}