Handling dynamic headers from transformFile · Issue #224 · react-component/upload · GitHub
Skip to content

Handling dynamic headers from transformFile #224

Open

Description

@michaelfarrell76

Hi there!

We have a situation where we use rc-upload in the following manner:

  • User selects file on file system
  • We use transformFile to encrypt the contents of that file on the browser
  • The encryption generates additional metadata that we want to pass as headers
  • This metadata is not available until transformFile is completed.

It would be great if headers could also be a function that takes in the result of transformFile and returns the headers.

I tried to make a PR for this but it was not possible bc of permissions.

The changes to do this are pretty quick:
in AjaxUploader.tsx

change

headers: props.headers,

to

headers: typeof props.headers === 'function' ? props.headers(transformedFile) : props.headers,

and also update the README comment to me

|headers| object/function(blob) | {} | http headers to post, available in modern browsers. Can be a function that takes in the result of transformFile |

Activity

  1. changed the title [-]Handling dynamic headers[/-] [+]Handling dynamic headers from transformFile[/+] on Jan 22, 2020
  2. magicdawn commented on Feb 11, 2020

    @magicdawn

    special use can be implemented via customReuqest,
    you can use transformedFile.headers & set to headers via customRequest

  3. michaelfarrell76 commented on Feb 13, 2020

    @michaelfarrell76
    Author

    ya ended up doing it this way, had to do a lot of copy and paste but it works

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions