@org_educaresco/viam.profileimage
Version:
A React component that show Image Perfil.
49 lines (45 loc) • 1.22 kB
JavaScript
import axios from "axios";
export const formatTobase64 = (photo, nameFile) => {
const response = {
isOK: true,
data: []
};
if (photo !== "" && photo !== "image-invalid") {
let photo64bit = photo.split("data:image/png;base64,");
if (photo64bit.length === 1) {
photo64bit = photo.split("data:image/jpg;base64,");
if (photo64bit.length === 1) {
photo64bit = photo.split("data:image/jpeg;base64,");
if (photo64bit.length === 1) {
response.isOK = false;
}
}
}
response.data = {
name: nameFile,
base64: response.isOK === true ? photo64bit[1] : []
};
} else {
response.isOK = false;
}
return response;
};
export const addDataPhote = (dataPhoto, photo, nameFile) => {
const { isOK, data } = formatTobase64(photo, nameFile);
if (isOK) {
dataPhoto.push(data);
}
};
export const loadToS3 = (configLoadToS3, dataPhoto) => {
return axios({
method: "POST",
url: configLoadToS3.aws_url,
data: {
bucket: configLoadToS3.aws_name_bucket,
images: dataPhoto
},
headers: {
authorization: configLoadToS3.aws_token
}
});
};