Skip to content

feat: brower platform add data protocol.#4804

Merged
jasonsaayman merged 3 commits intoaxios:v1.xfrom
0x30:v1.x
Aug 1, 2022
Merged

feat: brower platform add data protocol.#4804
jasonsaayman merged 3 commits intoaxios:v1.xfrom
0x30:v1.x

Conversation

@0x30
Copy link
Copy Markdown

@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
Copy Markdown
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.

2 participants