-
-
Save uno-de-piera/db8a76ac315fea4596c0dcd784a1e3a3 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import { Storage } from "aws-amplify"; | |
export default class S3Utils { | |
static async uploadImage(image, folder) { | |
// parseamos el base64 para obtener los datos que necesitamos para crear la imagen | |
const base64Parsed = new Buffer( | |
image.replace(/^data:image\/\w+;base64,/, ""), | |
"base64" | |
); | |
// obtenemos la extensión | |
const type = image.split(";")[0].split("/")[1]; | |
// generamos un nombre aleatorio | |
const fileName = `${folder}/${Math.random() | |
.toString(36) | |
.substr(2, 15)}.${type}`; | |
// hacemos la subida a S3 diciéndole a Amplify que el contenido es un base64, así lo retorna Vuetify Image Input | |
const { key } = await Storage.put(fileName, base64Parsed, { | |
contentType: "image/jpg", | |
contentEncoding: "base64" | |
}); | |
// path del archivo en nuestro bucket de S3 | |
return key; | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment