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

feat: brower platform add data protocol. #4804

Merged
merged 3 commits into from Aug 1, 2022
Merged

feat: brower platform add data protocol. #4804

merged 3 commits into from Aug 1, 2022

Conversation

0x30
Copy link
Contributor

@0x30 0x30 commented Jun 23, 2022

export const useBase64ToFile = (
  src: string,
  name = "file.png",
  type = "image/png"
) => {
  return axios
    .get(`data:image/png;base64,${src}`, { responseType: "blob" })
    .then((res) => new File([res.data], name, { type }));
};

// now -> throw axiosError "Unsupported protocol data:"
// Since data is not currently supported, I have to

export const useBase64ToFile = (
  src: string,
  name = "file.png",
  type = "image/png"
) => {
  return fetch(`data:image/png;base64,${src}`)
    .then((res) => res.arrayBuffer())
    .then((res) => new File([res], name, { type }));
};

Fetch and XMLHttpRequest support data, so we have no reason to reject this scheme

@jasonsaayman
Copy link
Member

Thanks for the addition 😄

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

Successfully merging this pull request may close these issues.

None yet

2 participants