0
votes

var selectedfile;
function upload()
{
  selectedfile= document.getElementById("file");
  var filename=selectedfile.files.item(0).name;
  var storageRef=firebase.storage().ref('/Images/'+filename);
  var uploadTask=storageRef.put(selectedfile);
  uploadTask.on('state_changed',function(snapshot){},function(errors){},
    function(){
      var downloadUrl=uploadTask.snapshot.downloadUrl;
      console.log(downloadUrl);
    });
}
<input type="file" name="fileid" id="file">
<button onclick="upload();" id="selbt">Upload</button>

While I am trying to upload images to my Firebase Storage it threw my some uncaught exception like:

An uncaught error is shown in the Console. It is saying invalid argument as 'put'. Can anyone please help in solving this issue.

2
Declare a form and use the next attribute enctype="multipart/form-data - Gerardo BLANCO
I couldn't get you - Badhusha
Will answer for more code space but cant really test it with out the firebase dependency - Gerardo BLANCO

2 Answers

0
votes
<form method="post" enctype="multipart/form-data">
 <div>
   <label for="file">Choose file to upload</label>
   <input type="file" id="file" name="file" multiple>
 </div>
 <div>
   <button>Submit</button>
 </div>
</form>
0
votes

Try

var filename=selectedfile.files[0].name;