2022-03-16 21:02:34 +00:00
|
|
|
// import fetch from "fetch"
|
2022-03-28 17:59:07 +00:00
|
|
|
import axios, { AxiosRequestConfig } from "axios";
|
2022-03-16 21:02:34 +00:00
|
|
|
|
|
|
|
export async function uploadToImgur(dataURL, handleGettingImgurlImage) {
|
2022-03-27 21:10:31 +00:00
|
|
|
let request: AxiosRequestConfig = {
|
2022-03-16 21:02:34 +00:00
|
|
|
method: "post",
|
|
|
|
url: "https://api.imgur.com/3/image",
|
|
|
|
headers: {
|
|
|
|
Authorization: "Bearer 8e9666fb889318515a62208560d4e8393dac26d8",
|
|
|
|
},
|
|
|
|
data: {
|
|
|
|
type: "base64",
|
|
|
|
image: dataURL.split(",")[1],
|
|
|
|
},
|
2022-03-27 21:10:31 +00:00
|
|
|
// redirect: "follow",
|
2022-03-16 21:02:34 +00:00
|
|
|
};
|
|
|
|
let url;
|
|
|
|
try {
|
|
|
|
let response = await axios(request).then((response) => response.data);
|
|
|
|
// console.log(dataURL)
|
|
|
|
// console.log(response)
|
|
|
|
url = `https://i.imgur.com/${response.data.id}.png`;
|
|
|
|
} catch (error) {
|
|
|
|
console.log("error", error);
|
|
|
|
}
|
|
|
|
let errorImageURL = "https://i.imgur.com/qcThRRz.gif"; // Error image
|
|
|
|
url = url || errorImageURL;
|
|
|
|
handleGettingImgurlImage(url);
|
|
|
|
}
|