Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

File upload erroring with modified ActiveStorage::BaseController #50

Open
ImOnMars opened this issue Jan 2, 2020 · 1 comment
Open

Comments

@ImOnMars
Copy link

ImOnMars commented Jan 2, 2020

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
Copy link
Author

ImOnMars commented Jan 2, 2020

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

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant