如何将blob上传为文件?

时间:2017-01-04 20:31:07

标签: javascript firebase firebase-storage

我尝试使用下面的代码将blob上传到firebase。但是,我没有成功。你能帮我吗?

我的参考:https://firebase.google.com/docs/storage/web/upload-files#upload_from_a_blob_or_file

var auth = firebase.auth();
var storageRef = firebase.storage().ref();

function mUpload() {
var i_note = document.getElementById('note').value;

var mblob = new Blob([i_note], {type: "text/plain;charset=utf-8"});

// var file = new File([mblob], "filename")
var file = new File([mblob], "filename", {type: 'text/plain', lastModified: Date.now()});

var metadata = {
'contentType': file.type
};

storageRef.child('Books/myfile.txt').put(file, metadata).then(function(snapshot) {
var url = snapshot.metadata.downloadURLs[0];
}).catch(function(error) {
console.error('Upload failed:', error);
});   
}

非常感谢帮助......

0 个答案:

没有答案