reactjs React Axios,我想使用来自get API的配置文件用户映像

qlfbtfca  于 2023-01-25  发布在  React
关注(0)|答案(1)|浏览(104)

hi我想从后端发送的json中获取用户的照片,但是无法获取照片将显示在 Postman “imageName”中:“0fa6ee43-adac-4ee6-ae21-a84ff6cef891.jpg”,这是来自我后端的图像

const userToken = localStorage.getItem("token");
AxiosBaseUrl.get("url", {
  headers: {
    Authorization: `Bearer ${userToken}`,
  },
}).then((response) => {
  const image = new File([response.data.imageName], 'profileName', {type: 'image/jpeg'});
  console.log(image);
  setProfileImage(image);
  setEmail(response.data.email);
  setFullName(response.data.fullName);
  setGender(response.data.gender);
  setPhoneNumber(response.data.phoneNumber);
  console.log(response);
});

 <img
              accept="image/*"
              src={URL.createObjectURL(profileImage)}
              alt="profile_image"
            />

感谢大家

bzzcjhmw

bzzcjhmw1#

我探索了许多途径,包括:斑点

相关问题