home · Posts · Archive · Tags

20231107-imgbb

免費圖片上傳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

👈Go Back

@alanhc