gpt4 book ai didi

javascript - 错误: 'invalid argument' when trying to upload a file to firebase storage

转载 作者:行者123 更新时间:2023-11-28 03:16:27 25 4
gpt4 key购买 nike

我在尝试将图像上传到 Firebase 存储时收到以下错误:

v {code_: "storage/invalid-argument", message_: "Firebase Storage: Invalid argument in `put` at index 0: Expected Blob or File.", serverResponse_: null, name_: "FirebaseError"}
name: (...)
code: (...)
message: (...)
serverResponse: (...)
code_: "storage/invalid-argument"
message_: "Firebase Storage: Invalid argument in `put` at index 0: Expected Blob or File."
serverResponse_: null
name_: "FirebaseError"
__proto__: Object

这是我的代码

<div>
<h1>Upload file</h1>
<label class="upload-group">
<input type="file" onchange="handleFileSelect(this)" id="file">
</label>
<button type="button" id="uploadButton" onclick="uploadFile()">Submit</button>
</div>

function handleFileSelect() {
$(".upload-group").show();
return document.getElementById('file').files[0];
};


function uploadFile() {
var filename = handleFileSelect().name;
var storageRef = firebase.storage().ref('/dogImages/' + filename);
var uploadTask = storageRef.put(selectedFile);

我已经尝试了几个小时将图像上传到 Firebase 存储,但是没有成功。我假设问题可能出在我的 put() 函数上。

最佳答案

该错误与安全规则无关。您正在向 put() 传递无效参数。仔细阅读消息:

Firebase Storage: Invalid argument in put at index 0: Expected Blob or File."

您传递了一个字符串,但 API 需要一个 Blob 或 File 对象。您可能想查看documentation for uploading files有关如何正确执行此操作的示例。

关于javascript - 错误: 'invalid argument' when trying to upload a file to firebase storage,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/59601666/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com