2017-03-08 7 views
5

我正在使用針對Android應用程序的react-native。並使用axios作爲http庫。當我嘗試發送通過HTTP POST一個Blob對象我會得到以下錯誤:在React原生應用程序中獲得'分配源之一在原型鏈上具有可枚舉鍵'

HTTP Failure in Axios TypeError: One of the sources for assign has an enumerable key on the prototype chain. Are you trying to assign a prototype property? We don't allow it, as this is an edge case that we do not support. This error is a performance optimization and not spec compliant. 

下面是我用來在表單添加數據的blob對象的代碼:

let data = new FormData() 
    data.append('image', decodeBase64Image(image)); 
下面

是代碼解碼base64圖像。下面的代碼在我的網站應用程序中正常工作。

export const decodeBase64Image = (dataURI) => { 
    let byteString; 
    if (dataURI === undefined) { 
    return undefined 
    } 
    if (dataURI.split(',')[0].indexOf('base64') >= 0) 
    byteString = atob(dataURI.split(',')[1]); 
    else 
    byteString = unescape(dataURI.split(',')[1]); 

    // separate out the mime component 
    let mimeString = '' 
    if (dataURI.split(',')[0] != undefined && dataURI.split(',')[0].split(':')[1] != undefined) { 
    mimeString = dataURI.split(',')[0].split(':')[1].split(';')[0] 
    } 
    // write the bytes of the string to a typed array 
    let ia = new Uint8Array(byteString.length); 
    for (let i = 0; i < byteString.length; i++) { 
    ia[i] = byteString.charCodeAt(i); 
    } 
    return new Blob([ia], {type: mimeString}); 
} 

回答

0

問題的根源在於原生做出反應開發者做出不符合規範兼容的性能優化(這就是爲什麼代碼工作在您的網站,但不是你的陣營原生應用)。有關更多詳細信息,請參閱我在此處打開的問題:https://github.com/facebook/react-native/issues/16814

作爲解決方法,您可以使用react-native-fetch-blob。我遇到了同樣的錯誤,並且react-native-fetch-blob爲我解決了這個問題。

相關問題