简体   繁体   English

无法在'FileReader'上执行'readAsText':参数1不是'Blob'类型

[英]failed to execute 'readAsText' on 'FileReader' :parameter 1 is not of type 'Blob'

I got the errors failed to execute 'readAsText' on 'FileReader': parameter 1 is not of type' Blob'.My library is 0.10.8 version. 我遇到了无法在'FileReader'上执行'readAsText'的错误:参数1不是'Blob'类型。我的库是0.10.8版本。 I have tried to downgrade react native fetch blob to 0.9.5 but i got another error. 我曾尝试将原生抓取Blob降级到0.9.5,但又遇到另一个错误。

listeners is not defined 未定义侦听器

i have read problem at github, but i don't really understand with their solutions i confused right now. 我在github上读过问题,但是我现在对他们的解决方案不太了解。

const Blob = RNFetchBlob.polyfill.Blob

const fs = RNFetchBlob.fs

window.XMLHttpRequest = RNFetchBlob.polyfill.XMLHttpRequest

window.Blob = Blob

​

const screenWidth = Dimensions.get('window').width

​

const uploadImage = (uri, imageName, mime = 'image/jpg') => {

return new Promise((resolve, reject) => {

const uploadUri = Platform.OS === 'ios' ? uri.replace('file://', '') : uri

let uploadBlob = null

const imageRef = firebaseApp.storage().ref('posts').child(imageName)

fs.readFile(uploadUri, 'base64')

.then((data) => {

return Blob.build(data, { type: `${mime};BASE64` })

})

.then((blob) => {

uploadBlob = blob

return imageRef.put(blob, { contentType: mime })

})

.then(() => {

uploadBlob.close()

return imageRef.getDownloadURL()

})

.then((url) => {

resolve(url)

})

.catch((error) => {

reject(error)

})

})

}

I solved it by resetting the window.XMLHttpRequest to it's original state after finished using the fetch blob for uploading my image to cloud. 我完成了使用fetch blob将图像上传到云后,通过将window.XMLHttpRequest重置window.XMLHttpRequest原始状态来解决该问题。 Hope it helps :) 希望能帮助到你 :)

 const Blob = FetchBlob.polyfill.Blob; // Keep an original copy of window.XMLHttpRequest before set it to FetchBlob.polyfill.XMLHttpRequest const oriWindowXMLHttpRequest = window.XMLHttpRequest; window.XMLHttpRequest = FetchBlob.polyfill.XMLHttpRequest; window.Blob = Blob; return new Promise((resolve, reject) => { Blob.build(imageFile, { type: mime }) .then(blob => { uploadBlob = blob; return imageRef.put(blob, { contentType: mime }); }) .then(() => { uploadBlob.close(); return imageRef.getDownloadURL(); }) .then(url => { // Reset it to the original WindowXMLHttpRequest after the task has been done completely window.XMLHttpRequest = oriWindowXMLHttpRequest; resolve(getSuccessResponse(url)); }) .catch(error => { // Reset it to the original WindowXMLHttpRequest after the task has been done completely window.XMLHttpRequest = oriWindowXMLHttpRequest; showToast(getErrorMessage(error)); reject(getFailResponse(error)); }); }); 

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 抛出'FileReader'的fileReader.readAsText():参数1不是'Blob'类型 - fileReader.readAsText() throwing 'FileReader': parameter 1 is not of type 'Blob' 无法在“FileReader”上执行“readAsArrayBuffer”:参数 1 的类型不是“Blob” - Failed to execute 'readAsArrayBuffer' on 'FileReader': parameter 1 is not of type 'Blob' 未捕获的类型错误:无法在“FileReader”上执行“readAsDataURL”:参数 1 的类型不是“Blob” - Uncaught TypeError: Failed to execute 'readAsDataURL' on 'FileReader': parameter 1 is not of type 'Blob' 类型错误:无法在“FileReader”上执行“readAsDataURL”:参数 1 的类型不是“Blob” - TypeError: Failed to execute 'readAsDataURL' on 'FileReader': parameter 1 is not of type 'Blob' 未捕获的TypeError:无法在“ FileReader”上执行“ readAsBinaryString”:参数1的类型不是“ Blob” - Uncaught TypeError: Failed to execute 'readAsBinaryString' on 'FileReader': parameter 1 is not of type 'Blob' 有时会:无法在“FileReader”上执行“readAsDataURL”:参数 1 不是“Blob”类型 - Sometimes getting: Failed to execute 'readAsDataURL' on 'FileReader': parameter 1 is not of type 'Blob' Angular.js:未捕获的TypeError:无法在“ FileReader”上执行“ readAsDataURL”:参数1的类型不是“ Blob” - Angularjs : Uncaught TypeError: Failed to execute 'readAsDataURL' on 'FileReader': parameter 1 is not of type 'Blob' 拖放:未捕获类型错误:无法在“FileReader”上执行“readAsDataURL”:参数 1 不是“Blob”类型 - Drag and Drop: Uncaught TypeError: Failed to execute 'readAsDataURL' on 'FileReader': parameter 1 is not of type 'Blob' 将博客转换为 base64:TypeError:无法在“FileReader”上执行“readAsDataURL”:参数 1 不是“Blob”类型 - Converting blog to base64: TypeError: Failed to execute 'readAsDataURL' on 'FileReader': parameter 1 is not of type 'Blob' FileReader 错误参数 1 不是“Blob”类型 - FileReader error parameter 1 is not of type 'Blob'
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM