0
我有一个输入字段,用户可以在其中选择要上传的图像,然后我需要发送到云存储。问题是,我不知道如何获取他们选择的文件。我看到很多问题,例如this,this,this等。我看到的大多数问题(如this之一)都要求在上传之前预览图像。我不认为我需要预览图像,我只想上传它。我该怎么做呢?这是我现在的代码:如何从输入字段上传图片到firebase云存储?
function addImage() {
$("#addImage").append('\
<input type="file" id="image" accept="image/*">\
<button type="submit">ok</button>\
<button onclick="cancelAddImage()">cancel</button>');
$("#addImage").submit(function() {
var image = $("#image").files;
console.log(image);
storage.ref("images").put(image).then(function(snapshot) {
console.log('Uploaded a file!');
});
});
}
console.log()为此提供了“未定义”。我也试过.files[0]
而不是.files;
,还有很多其他的。