Skip to content

Instantly share code, notes, and snippets.

@OberdanBrito
Last active August 18, 2021 14:25
Show Gist options
  • Save OberdanBrito/1e1d94eb43d10c9267a29a616ba76da3 to your computer and use it in GitHub Desktop.
Save OberdanBrito/1e1d94eb43d10c9267a29a616ba76da3 to your computer and use it in GitHub Desktop.
Exemplo de conversão de base64 para blob e upload do blob
UploadImagens(Conteudo) {
return new Promise((resolve) => {
fetch(Conteudo)
.then(res => res.blob())
.then(res => {
let fd = new FormData();
fd.append("blob", res, `${''.uuid()}.${Conteudo.substring("data:image/".length, Conteudo.indexOf(";base64"))}`);
fetch(this.upload, {
method: 'POST',
body: fd
})
.then(response => response.json())
.then(response => {
resolve(`${this.download}${response.name}`)
})
.catch(reason => {
console.debug(reason)
});
})
})
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment