将MP3上传到使用React Native Expo的Firebase存储
我正在尝试使用Expo上传MP3到Firebase存储,并进行反应本机。到目前为止,我将文件放入了Firebase存储中,但是它只有9个比例,所以我做错了什么。如下所示,我尝试使用斑点尝试了一下。
这是firebase存储文件夹的屏幕截图,显示上传的文件,但不是所述文件的数据:
任何帮助非常感谢,我觉得我错过了与文件一起实际上上传数据的步骤。
export default function SongPicker() {
const [song, setSong] = useState(null);
//Get current user through authentication
const user = auth.currentUser;
const pickDocument = async () => {
let result = await DocumentPicker.getDocumentAsync({});
// Fetch the photo with it's local URI
const response = fetch(result.uri);
alert(result.uri);
console.log(result);
const file = new Blob(
[response.value], {
type: 'audio/mpeg'
});
console.log('do we see this?');
try {
//Create the file reference
const storage = getStorage();
const storageRef = ref(storage, `songs/${user.uid}/${result.name}`);
// Upload Blob file to Firebase
const snapshot = uploadBytes(storageRef, file, 'blob').then((snapshot) => {
console.log('Uploaded a song to firebase storage!');
});
setSong(result.uri);
} catch (error) {
console.log(error);
}
}
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
fetch()
返回诺言,因此您也应该添加等待此期待。然后尝试在 blob()方法“>响应:
uploadbytes
中的第三个参数应该是上传元数据对象,但您可以在此处跳过:The
fetch()
returns a Promise so you should add an await for that as well.Then try using
blob()
method on the Response:The third param in
uploadBytes
should be upload metadata object but you can skip that here: