我在Angular2中遇到问题:我有媒体上传模块(图像/视频)。所以上传模块工作正常但在我尝试观看视频或查看图像文件上传文件后,我收到404 Not Found错误。但如果我运行构建并再次刷新它我可以观看视频或查看图像文件。我做错了什么,或者我们可以解决这个问题吗?
获取http://localhost:4200/dist/assets/mediauploads/Desktop%20(19).jpg 404(未找到)
//This is my node js code
socket.on('Upload', function (data){
var Name = data['Name'];
Files[Name]['Downloaded'] += data['Data'].length;
Files[Name]['Data'] += data['Data'];
if(Files[Name]['Downloaded'] == Files[Name]['FileSize']) //If File is Fully Uploaded
{
fs.write(Files[Name]['Handler'], Files[Name]['Data'], null, 'Binary', function(err, Writen){
var inp = fs.createReadStream("./src/assets/temp/" + Name);
var out = fs.createWriteStream("./src/assets/mediauploads/" + Name);
inp.pipe(out);
inp.on("end", function() {
var path="./src/assets/temp/" + Name;
var tempFile = fs.openSync(path, 'r');
if(fs.existsSync(path)){
fs.closeSync(tempFile);
fs.unlinkSync(path);
socket.emit('Done', {'Image' : './src/assets/mediauploads/' + Name});
}
});
});
}
else if(Files[Name]['Data'].length > 10485760){ //If the Data Buffer reaches 10MB
fs.write(Files[Name]['Handler'], Files[Name]['Data'], null, 'Binary', function(err, Writen){
Files[Name]['Data'] = ""; //Reset The Buffer
var Place = Files[Name]['Downloaded'] / 524288;
var Percent = (Files[Name]['Downloaded'] / Files[Name]['FileSize']) * 100;
socket.emit('MoreData', { 'Place' : Place, 'Percent' : Percent});
});
}
else
{
var Place = Files[Name]['Downloaded'] / 524288;
var Percent = (Files[Name]['Downloaded'] / Files[Name]['FileSize']) * 100;
socket.emit('MoreData', { 'Place' : Place, 'Percent' : Percent});
}
});
答案 0 :(得分:0)
运行ng build
时,角度应用内置于dist
文件夹中。我的猜测是你的应用程序安装方式实际上是将图像上传到src/assets
文件夹中。
当您从dist
文件夹运行应用时,您新上传的图片/视频将不可见。重建应用程序时,文件将复制到dist
文件夹并变为可访问。