gpt4 book ai didi

node.js - 上传媒体文件后无法在 Angular 2中播放该文件,显示404未找到

转载 作者:太空宇宙 更新时间:2023-11-04 02:04:47 24 4
gpt4 key购买 nike

我在 Angular2 中遇到问题:我有媒体上传模块(图像/视频)。因此,上传模块工作正常,但上传文件后,当我尝试观看视频或查看图像文件时,出现 404 Not Found 错误。但是如果我运行 ng build 并再次刷新它,我可以观看视频或查看图像文件。我做错了什么或者我们可以用某种方式处理这个问题吗?

获取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});
}
});

最佳答案

当您运行ng build时, Angular 应用程序将内置到dist文件夹中。我的猜测是,您的应用程序设置方式实际上是将图像上传到您的 src/assets 文件夹中。当您从 dist 文件夹运行应用程序时,您新上传的图像/视频不可见。当您重建应用程序时,文件将被复制到 dist 文件夹并可供访问。

关于node.js - 上传媒体文件后无法在 Angular 2中播放该文件,显示404未找到,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/44738262/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com