我尝试使用示例文件上传器https://github.com/pc-magas/dummy-azure-file-upload)https://atmospherejs.com/jamesfebin/azure-blob-upload
所以我创建了名为imports/api/FileUpload.js
的以下文件:
import { Meteor } from 'meteor/meteor';
import { Mongo } from 'meteor/mongo';
import FileUploadSetings from '../settings/fileUploadSettings.js'
const UploadedFile = new Mongo.Collection('file');
Meteor.methods({
'fileStorage.uploadFile'(file) {
console.log("File To be uploaded",file)
var response=file.azureUpload(file.name,FileUploadSetings.account,FileUploadSetings.key,FileUploadSetings.container)
return response
}
});
适当的前端:
import React, { Component } from 'react';
import { UploadedFile } from '../api/FileUpload.js';
class File extends Component {
changeFile(e) {
e.preventDefault()
var targetElem=e.target
files = document.getElementById('fileUpload');
file = files.files[0]
AzureFile.upload(file,'fileStorage.uploadFile',function(err,value){
if(err){
console.log(err)
throw err;
return;
}
console.log(value);
});
}
render() {
return (
<form onSubmit={ this.changeFile.bind(this) }>
<label>
<input id="fileUpload" type="file" name="file" />
</label>
<button type="submit">UploadFile</button>
</form>
)
}
}
export default File;
但在我的浏览器上,我收到以下错误:
模拟调用'fileStorage.uploadFile'的效果时出现异常TypeError:file.azureUpload不是函数 Καταγραφήστοίβας: fileStorage.uploadFile@http://localhost:3000/app/app.js?hash=130e7c3d782ccd6552701f8726699ac4a8c57f12:85:24 应用/ stubReturnValue&LT; @ http://localhost:3000/packages/ddp-client.js?hash=c9ca22092a3137a7096e8ab722ba5ab8eedb9aec:4076:20 withValue @ http://localhost:3000/packages/meteor.js?hash=27829e936d09beae3149ecfbf3332c42ccb1596f:1077:17 申请@ http://localhost:3000/packages/ddp-client.js?hash=c9ca22092a3137a7096e8ab722ba5ab8eedb9aec:4067:31 readNext /&LT; @ http://localhost:3000/packages/jamesfebin_azure-blob-upload.js?hash=8cbf5c2696876a426eda4183be8f4ce83c709a97:206:9 read/reader.onload@http://localhost:3000/packages/jamesfebin_azure-blob-upload.js?hash=8cbf5c2696876a426eda4183be8f4ce83c709a97:146:6 fileStorage.uploadFile@http://localhost:3000/app/app.js?hash=130e7c3d782ccd6552701f8726699ac4a8c57f12:85:24 应用/ stubReturnValue&LT; @ http://localhost:3000/packages/ddp-client.js?hash=c9ca22092a3137a7096e8ab722ba5ab8eedb9aec:4076:20 withValue @ http://localhost:3000/packages/meteor.js?hash=27829e936d09beae3149ecfbf3332c42ccb1596f:1077:17 申请@ http://localhost:3000/packages/ddp-client.js?hash=c9ca22092a3137a7096e8ab722ba5ab8eedb9aec:4067:31 readNext /&LT; @ http://localhost:3000/packages/jamesfebin_azure-blob-upload.js?hash=8cbf5c2696876a426eda4183be8f4ce83c709a97:206:9 read/reader.onload@http://localhost:3000/packages/jamesfebin_azure-blob-upload.js?hash=8cbf5c2696876a426eda4183be8f4ce83c709a97:146:6 meteor.js:932:11
你有什么想法,为什么我会解决它?