Got 'One of the sources for assignment has an enumerated key in the prototype chain' on React native app

I am using action-native for an Android application. And use axios as an http library. When I try to send a Blob object via http post, I will get below error:

 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. 

Below is the code that I used to add the blob object to the form data:

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

below is the code for decoding a base64 image. And below code works fine in one of my web apps.

 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}); } 
+5
source share
1 answer

The root of the problem is that the React Native developers made a performance optimization that did not meet the specification (therefore, the code works on your website, but not in your React Native application). For more information, see the Problem I Discovered Here: https://github.com/facebook/react-native/issues/16814

As a workaround, you can use react-native-fetch-blob . I ran into the same error as you, and reaction-native-fetch-blob solved it for me.

0
source

Source: https://habr.com/ru/post/1265162/


All Articles