【发布时间】:2018-04-09 21:03:28
【问题描述】:
我有一个输入字段,用户可以在其中选择要上传的图像,然后我需要发送到云存储。问题是,我不知道如何获取他们选择的文件。我看到很多问题,如this、this、this 等。我看到的大多数问题,如this 之一,都是要求在上传之前预览图像。我不认为我需要预览图像,我只想上传它。我该怎么做呢?这是我当前的代码:
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;,还有很多其他的。
【问题讨论】:
标签: javascript jquery image firebase firebase-storage