react上传java_Meteor React ReactRouter文件上传

我目前正在使用Meteor,ReactJS和React Router(用于路由)开发应用程序 . 我有一个要求,即用户应该能够上传压缩的网站,而Meteor应用程序需要将此网站显示为其中一个页面的一部分 .

典型的zip文件将包含与下面类似的模式,

ZippedFolder

|-- css

| |-- bootstrap.css

| |-- bootstrap.min.css

| +-- style.css

|-- js

| |-- bootstrap.js

| |-- bootstrap.min.js

| +-- script.js

+- index.html

我已经设置了CollectionFS来将zip文件存储到文件系统中并使用meteorhacks:npm和几个npm包,我能够将该文件解压缩到已知位置 .

HTMLContent = new FS.Collection("html_content", {

stores: [new FS.Store.FileSystem("html_content"]

});

HTMLContent.on('stored', Meteor.bindEnvironment(function (fileObj) {

let unzip = Meteor.npmRequire('unzip'),

fs = Meteor.npmRequire('fs'),

path = fs.realpathSync(process.cwd() + '/../../../cfs/files/html_content/'),

file = fs.realpathSync(path + '/' + fileObj.copies.html_content.key),

output = path + '/' + fileObj._id;

// TODO: Not the best ways to pick the paths. For demo only.

if (!fs.existsSync(output)) {

fs.mkdirSync(output);

}

fs.createReadStream(file).pipe(unzip.Extract({

path: output

}));

}));

在React组件上我使用以下代码片段上传压缩的HTML内容 .

handleZIPUpload(event) {

FS.Utility.eachFile(event, function(file) {

HTMLContent.insert(file, function(err, fileObj) {

if (err) {

console.log(err);

} else {

console.log(fileObj);

}

});

});

},

render(){

return (

)

}

上传和解压缩工作 . 但是,CollectionFS不提供解压缩路径中的HTML或其他内容 .

http://meteorhost/cfs/files/html_content/file_id/index.html

我也尝试将html内容解压缩到meteor文件夹结构的公共文件夹 . 但是,meteor文档指出公用文件夹适用于静态资产 . 因为它维护公用文件夹中资产的索引 . 因此,需要重新启动服务器才能更新索引 .

是否还有其他位置可以放置可以按原样提供的HTML内容?

更新我通过设置nginx虚拟目录并将文件上传到该位置来排序此问题,以便nginx将提供HTML内容 .

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值