URL.createObjectURL does not work in react-native, Is there an alternative to create a url?

北慕城南 提交于 2021-02-09 09:19:18

问题


I am trying to display pdf file in react-native app.

Here is my code: getting blob from api :

Blob {
  "_data": Object {
    "blobId": "85225e45-7f45-463b-bd62-a9170551a3b7",
    "lastModified": undefined,
    "offset": 0,
    "size": 3028,
    "type": "application/pdf",
  },
}

Note: After converting to base64Data i am able to render images but not pdf files.

const fileReaderInstance = new FileReader();
fileReaderInstance.readAsDataURL(response.data);
fileReaderInstance.onload = () => {
    base64data = fileReaderInstance.result;
     dispatch({
            type: OPEN_DOCUMENT, url: base64data 
        });
}

And in render

<WebView 
   source={{ uri: url }} 
   originWhitelist={['*']}
 />

(working fine for images)

<Image source={{uri: url}} style={{ height: 400, width: 300, }} />

来源:https://stackoverflow.com/questions/59622283/url-createobjecturl-does-not-work-in-react-native-is-there-an-alternative-to-cr

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!