上传后,媒体文件无法播放角度为2的文件,显示未找到404 [英] After upload a media file can not play the file in angular 2, shows 404 not found
问题描述
我在Angular2中遇到问题:我具有用于媒体上传的模块(图像/视频).因此,上载模块工作正常,但是当我尝试观看视频或查看图像文件上载文件后,出现404未找到错误.但是,如果我运行ng build并再次刷新它,我可以观看视频或查看图像文件.我是在做错什么,还是可以用某种方式解决呢?
I have a problem in Angular2: I have module for media upload (Images/Videos). So upload module is working perfect but after uploading the file when I try to watch the video or view the image file, I get a 404 Not Found error. But if i run ng build and refresh it again I can watch the video or view the image files. Am i doing something wrong or we can handle this with someway?
GET http://localhost:4200/dist/assets/mediauploads/Desktop%20(19).jpg 404(未找到)
GET http://localhost:4200/dist/assets/mediauploads/Desktop%20(19).jpg 404 (Not Found)
//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});
}
});
推荐答案
当您运行 ng build
时,Angular应用程序将内置在 dist
文件夹中.我的猜测是,您的应用程序设置方式实际上是将图像上传到您的 src/assets
文件夹中.从 dist
文件夹运行应用程序时,新上传的图像/视频不可见.重建应用程序时,文件将复制到 dist
文件夹并可以访问.
When you run ng build
the angular app is built into the dist
folder. My guess is you have your app setup in such a way you are actually uploading the image into your src/assets
folder.
As you are running the app from the dist
folder your newly uploaded image/video is not visible. When you rebuild the app the file is copied to the dist
folder and becomes accesible.
这篇关于上传后,媒体文件无法播放角度为2的文件,显示未找到404的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!