title: 20231107-imgbb date: 2023-11-07 tags:
- upload
- image
免費圖片上傳api
const onDrop = useCallback((acceptedFiles: any) => {
acceptedFiles.forEach((file: any) => {
const reader:any = new FileReader()
reader.onabort = () => console.log('file reading was aborted')
reader.onerror = () => console.log('file reading has failed')
reader.onload = async () => {
const base64String:any = reader.result.split(',')[1];
console.log(base64String);
let data = new FormData()
data.append("image", base64String)
fetch(`https://api.imgbb.com/1/upload?expiration=600&key=${api_key}`, {
method: "POST",
body:data
}).then((res)=>console.log(res))
}
reader.readAsDataURL(file)
})
}, [])
Ref
- https://api.imgbb.com/