【发布时间】:2021-06-20 21:46:54
【问题描述】:
我在我的项目中使用 nextjs 和 cloudinary-react:
这是我上传功能的代码库:
const uploadImage = () => {
const formData = new FormData();
formData.append("file", imageSelected);
formData.append("upload_preset", "teammateme");
axios.post("https://api.cloudinary.com/v1_1/teammateme/image/upload", formData)
.then((response) => {
console.log(response);
});
};
return (
<Card className="profile--card_container">
<CardContent>
{picture ? (
<div>
<Avatar
src={picture}
alt="Avatar"
className="avatar--profile_image"
/>
<input
type="file"
onChange={(event) => {
setImageSelected(event.target.files[0]);
}}
/>
<button onClick={uploadImage}>Submit</button>
</div>
) : (
<AccountCircleIcon className="avatar--profile_image" />
)}
)
如何制作用户头像的上传图片?
【问题讨论】:
-
你到底想要什么? api调用成功后通过api发送图片到服务器还是更新UI?
-
@agentp 只是更新我的控制台的图像
标签: reactjs cloudinary