Home  >  Q&A  >  body text

How to convert blob to URL in ReactNative

<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粉659518294P粉659518294458 days ago617

reply all(1)I'll reply

  • P粉493313067

    P粉4933130672023-08-11 14:57:45

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

    onSuccess:(blobData)=>{
       const dataUrl = URL.createObjectURL(blobData);
       //现在您拥有了URL,可以根据您的需求下载文件或在浏览器中打开
    }

    reply
    0
  • Cancelreply