如何检查文件大小的大小和维度反应原生?

问题描述

嘿,我正在从 API 获取详细信息,其中的图像也将出现,但我如何检查文件的大小和尺寸。我正在使用 Axios 获取数据?

解决方法

由于您的 API 返回一个 URI,您可以使用 Image 组件获取尺寸

Image.getSize(uri,(width,height)=>console.log(width,height)) 

对于 size ,您可以使用 fetch 或 Axios 与图像 URI 然后检查返回的请求。您可以在获取图像 URI 后直接添加

fetch(uri).then(response => console.log(response.headers.get("content-length")))
,

您可以使用此代码获取图像大小

const myUri= "https://cdn.pixabay.com/photo/2015/03/04/22/35/head-659652_960_720.png";
Image.getSize(myUri,height)=>console.log("image size",width,"x",height))