Warning: file_get_contents(/data/phpspider/zhask/data//catemap/9/javascript/461.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181

Warning: file_get_contents(/data/phpspider/zhask/data//catemap/8/perl/11.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Javascript 如何在react native中下载缓冲区数据文件或blob文件?_Javascript_Node.js_React Native_Ecmascript 6 - Fatal编程技术网

Javascript 如何在react native中下载缓冲区数据文件或blob文件?

Javascript 如何在react native中下载缓冲区数据文件或blob文件?,javascript,node.js,react-native,ecmascript-6,Javascript,Node.js,React Native,Ecmascript 6,我正在尝试在react native中使用axios下载文件。我得到了一个名为arrayBuffer的响应,其中包含init8Array、init16Array和unit8Array,然后我将整个响应转换为unit8Array,但我正在尝试将该unit8Array转换为字符串文件,它显示了我无法理解的意外数据。请帮助我解决此问题。我还使用react native fetch blob 以下是我的回应: 这是我的密码:- export const getDocumentDetail = (re

我正在尝试在react native中使用axios下载文件。我得到了一个名为arrayBuffer的响应,其中包含init8Array、init16Array和unit8Array,然后我将整个响应转换为unit8Array,但我正在尝试将该unit8Array转换为字符串文件,它显示了我无法理解的意外数据。请帮助我解决此问题。我还使用react native fetch blob

以下是我的回应:

这是我的密码:-

export const getDocumentDetail = (reference) => {
return async dispatch => {
    getToken().then(token =>{ 

AxiosBase.get('/document/'+reference,{
    responseType : 'arraybuffer',
    headers : {
        Authorization : 'Bearer '+token,
        Accept : 'application/pdf'
    }
})
.then(response => {
    console.log('Data',response.data)
    var bufferData = Buffer.from(response.data)
    var string = new TextDecoder("utf-8").decode(bufferData);
    console.log('Buffer : ',bufferData,string)
    dispatch({
        type : DOCUMENT_DETAIL,
        documentDetail : response.data
    })
})
.catch(error => {
    console.log('Documents Error : ',error)
})
    })
}
}

发布你的代码。请检查我的代码。你的文件是pdf,这是二进制数据,将其转换为文本文件不会有任何好处。您想对文件做什么?我只想在webview或pdf查看器中显示文件…或下载文件。。。