Error: ENOENT when renaming file in node/express app

前端 未结 2 1283
隐瞒了意图╮
隐瞒了意图╮ 2021-01-12 05:05

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

{ [Error: ENOENT, rename \'/tmp/64124a9886fdb03f1faee159bc5337         


        
相关标签:
2条回答
  • 2021-01-12 05:57

    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.

    0 讨论(0)
  • 2021-01-12 05:58

    Probably won't help the original poster, but in case somebody else runs into this issue and finds that the source and destination both appear to exist yet are running into this error, hopefully this will help. When I ran into this issue this is the exact problem I found - when I checked, both the source (full path to file) and destination (directory) was present, yet the rename was throwing ENOENT.

    In my case the solution was to recognize that I was using the asynchronous version of the directory creation function to create the destination directory. As a result, at the time the rename was attempt the destination directory did not yet exist, but as soon as I checked it had completed and the directory was there. Switching to the synchronous version of directory creation fixed the problem.

    0 讨论(0)
提交回复
热议问题