How to convert blob to URL in ReactNative
P粉659518294
P粉659518294 2023-08-10 15:38:09
0
1
615
<p>In my ReactNative application, I'm having trouble downloading files</p> <p>Backend response:</p> <p><code>{"_data": {"__collector": {}, "blobId": "E582A159-8E6E-48D2-B245-CA62A7005706", "name": "v1-download-proforma-invoice. json", "offset": 0, "size": 108769, "type": "application/json"}}</code></p> <p>I need to download this blob file to the device</p> <p>Looks like I need a data URL to download the file to my device</p> <p>How to generate this URL from this response in ReactNative? </p> <p>I use useMutation hook in react-query to handle this operation</p>
P粉659518294
P粉659518294

reply all(1)
P粉493313067

To download data, you can use useQuery and provide the attribute onSuccess:

onSuccess:(blobData)=>{
   const dataUrl = URL.createObjectURL(blobData);
   //现在您拥有了URL,可以根据您的需求下载文件或在浏览器中打开
}
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template
About us Disclaimer Sitemap
php.cn:Public welfare online PHP training,Help PHP learners grow quickly!