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});
}