繁体   English   中英

在 ios 上上传图像时,本机应用程序崩溃且没有日志

[英]react native app is crashing with no logs when uploading image on ios

when i try to use firebase uploadBytes on android it works fin but on ios whenever the video file is bigger than 2 mb the application crashes with no logs i tried using uploadBytesResumable and even tried to downgrade my firebase version to version 8 and no solution yet

const fetchImage = await fetch(localUri);
const imageBlob = await fetchImage.blob();
const storage = getStorage();
const upload = ref(storage, 'path_to_sotrage');
const uploadTask = await uploadBytesResumable(upload, imageBlob);
return await getDownloadURL(uploadTask.ref);

这个uploadBytes对我来说崩溃了,我不知道为什么。 但是,文档中的uploadBytesResumable模式正在工作并且看起来更稳定。 希望能帮助到你。

 import { getStorage, ref, uploadBytesResumable, getDownloadURL } from "firebase/storage"; const storage = getStorage(); // Create the file metadata /** @type {any} */ const metadata = { contentType: 'image/jpeg' }; // Upload file and metadata to the object 'images/mountains.jpg' const storageRef = ref(storage, 'images/' + file.name); const uploadTask = uploadBytesResumable(storageRef, file, metadata); // Listen for state changes, errors, and completion of the upload. uploadTask.on('state_changed', (snapshot) => { // Get task progress, including the number of bytes uploaded and the total number of bytes to be uploaded const progress = (snapshot.bytesTransferred / snapshot.totalBytes) * 100; console.log('Upload is ' + progress + '% done'); switch (snapshot.state) { case 'paused': console.log('Upload is paused'); break; case 'running': console.log('Upload is running'); break; } }, (error) => { // A full list of error codes is available at // https://firebase.google.com/docs/storage/web/handle-errors switch (error.code) { case 'storage/unauthorized': // User doesn't have permission to access the object break; case 'storage/canceled': // User canceled the upload break; //... case 'storage/unknown': // Unknown error occurred, inspect error.serverResponse break; } }, () => { // Upload completed successfully, now we can get the download URL getDownloadURL(uploadTask.snapshot.ref).then((downloadURL) => { console.log('File available at', downloadURL); }); } );

暂无
暂无

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

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM