本文介绍了错误:在node / express应用程序中重命名文件时,ENOENT的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

限时删除!!

我正在尝试在我的节点/ express应用程序中上传一个文件,我收到以下错误:

  [错误:ENOENT,重命名'/ tmp / 64124a9886fdb03f1faee159bc533776'] 
errno:34,
代码:'ENOENT',
路径:'/ tmp / 64124a9886fdb03f1faee159bc533776'}

/home/frankie/Projects/LP/routes/manager/deliverables.js:51
throw err;
^
错误:ENOENT,重命名'/ tmp / 64124a9886fdb03f1faee159bc533776'

是我的应用程序的相关代码:

  if(req.files.file.name!==&&& req.files.file.size!== 0){
//这将将上传的文件从tmp文件夹移动到uploads文件夹
fs.rename(req.files.file.path,app .get('loc')+uploads /+ name + - + id +/+ req.files.file.name,function(err){
if(err)throw err;

当我检查/ tmp中有什么文件时:

  fiega @ fiega:/ tmp $ ll 
total 56
drwxrwxrwt 12根根4096 Dec 12 11:33 ./
drwxr -xr-x 23根根4096 Sep 27 22:54 ../
-rw-rw-r-- 1 fiega fiega 903 Dec 12 11:33 13a26570f87297fd7f61785ef7d8772b
/ pre>

这是我如何使用身体解析器:

  app.use(表达。 cookieParser()); 
app.use(express.bodyParser());
app.use(express.methodOverride());

任何想法?我已经尝试更改我的整个应用程序的权限,但没有骰子。

解决方案

您检查了您正在使用的目标路径是否存在? (也许你的意思是 app.get('loc')+/ uploads / ...)



奇怪的是,当这种情况发生时(源文件存在和目标目录不存在),你得到的错误消息只指向源文件...所以检查是否不是问题。



请记住,如果要将上传的文件移动到 /a/b/c.txt / a



此外,如果您需要将文件移动到其他分区,那么您必须已经存在 / a / b 将不得不使用像这样的东西,或者你会得到一个 EXDEV 错误。


I am attempting to upload a file in my node/express app, and I am getting the following error:

{ [Error: ENOENT, rename '/tmp/64124a9886fdb03f1faee159bc533776']
  errno: 34,
  code: 'ENOENT',
  path: '/tmp/64124a9886fdb03f1faee159bc533776' }

/home/frankie/Projects/LP/routes/manager/deliverables.js:51
                            throw err;
                                  ^
Error: ENOENT, rename '/tmp/64124a9886fdb03f1faee159bc533776'

Here is the relevant code from my app:

if (req.files.file.name !== '' && req.files.file.size !== 0) {
    // this will move the uploaded file from the tmp folder to the uploads folder
    fs.rename(req.files.file.path, app.get('loc') +  "uploads/" + name + "-" + id + "/" + req.files.file.name, function (err) {
        if (err) throw err;

When I check what is in /tmp the file is there:

fiega@fiega:/tmp$ ll
total 56
drwxrwxrwt 12 root    root    4096 Dec 12 11:33 ./
drwxr-xr-x 23 root    root    4096 Sep 27 22:54 ../
-rw-rw-r--  1 fiega   fiega    903 Dec 12 11:33 13a26570f87297fd7f61785ef7d8772b

This is how I am using body parser:

app.use(express.cookieParser());
app.use(express.bodyParser());
app.use(express.methodOverride());

Any ideas? I have tried changing the permissions of my entire my app but no dice.

解决方案

Have you checked the destination path you are using exists? (maybe you mean app.get('loc') + "/uploads/"...)

Oddly when this happens (source file exists and destination directory not), the error message you get only points to the source file... So check if that's not the problem.

Remember if you want to move the uploaded file to /a/b/c.txt, both /a and /a/b must already exist.

Also, if you need to move the file to a different partition you will have to use something like this, or you will get a EXDEV error.

这篇关于错误:在node / express应用程序中重命名文件时,ENOENT的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

1403页,肝出来的..

09-06 12:41