react-activestorage-provider icon indicating copy to clipboard operation
react-activestorage-provider copied to clipboard

File upload erroring with modified ActiveStorage::BaseController

Open ImOnMars opened this issue 5 years ago • 1 comments

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.

ImOnMars avatar Jan 02 '20 15:01 ImOnMars

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 */);
}}

ImOnMars avatar Jan 02 '20 17:01 ImOnMars