Firebase错误Firebase存储:索引0中的put中无效的参数:预期的Blob或文件

时间:2019-02-11 16:17:40

标签: javascript firebase firebase-storage

我正在尝试将图像从本地设备上传到Firebase,但是当我打开应该执行此操作的网页时,出现此错误,并且它不起作用。 在单击提交按钮之前,我会收到此错误,因为我打开页面时会收到错误。

谢谢

<div id="filesubmit">
  <input type="file" id="caricaFile" class="file-select" accept="image/*"/>
  <button class="file-submit">SUBMIT</button>
</div>
          try{// Initialize Firebase
          var config = {
            apiKey: "AIzaSyA5-N-IEZDs9XYhmMCpSvyByp0OlTR-bhs",
            authDomain: "hackathon-76f01.firebaseapp.com",
            databaseURL: "https://hackathon-76f01.firebaseio.com",
            projectId: "hackathon-76f01",
            storageBucket: "hackathon-76f01.appspot.com",
            messagingSenderId: "1040124036693"
          };

          firebase.initializeApp(config);

          var storageRef = firebase.storage().ref(); // use the Blob or File API

        // Create a reference to 'mountains.jpg'
        var mountainsRef = storageRef.child('mountains.jpg');

        // Create a reference to 'images/mountains.jpg'
        var mountainImagesRef = storageRef.child('images/mountains.jpg');

        var file = document.getElementById("caricaFile").value

        storageRef.put(file).then(function(snapshot) {
          console.log('Uploaded a blob or file!');
        });

        var metadata = {
          contentType: 'image/jpeg',
        };

        // Upload the file and metadata
        var uploadTask = storageRef.child('images/mountains.jpg').put(file, metadata);
         }
        catch(err){
        console.log("errore");
        console.log(err);
        } 

1 个答案:

答案 0 :(得分:0)

我不知道是否需要try / catch块,但我想它应该像这样工作:

// Start transaction
MySqlTransaction transaction = connection.BeginTransaction();

MySqlCommand command = new MySqlCommand();
command.Connection = connection;
command.Transaction = transaction;

// Parent record
command.CommandText = "INSERT INTO film(Title, Director, Year, Category) VALUES (@Title, @Director, @Year, @Category) ";
command.Parameters.Add(new MySqlParameter("@Title", fm.Title));
command.Parameters.Add(new MySqlParameter("@Director", fm.Director));
command.Parameters.Add(new MySqlParameter("@Year", fm.Year));
command.Parameters.Add(new MySqlParameter("@Category",n));
command.ExecuteNonQuery();

// Child record        
command.CommandText = "INSERT INTO record (Film_id) VALUES (LAST_INSERT_ID())";
command.ExecuteNonQuery();

// Commit inserts
transaction.Commit();