Node.js用fs.renameSync報cross-device link not permitted錯誤

來源:互聯網
上載者:User

標籤:

今天閱讀了  Manuel Kiessling 的 《Node入門》   對node.js有一個大概的瞭解,在本書最後的一個例子上傳圖片時出現一些問題

問題:跨目錄重新命名檔案導致的問題 (fs.renameSync)

解決方案:

1.添加臨時路徑

 var form = new formidable.IncomingForm(); form.uploadDir=‘tmp‘; //臨時路徑

   

2.利用fs的createReadStream、createWriteSream和unlinkSync方法

 //   fs.renameSync(files.upload.path, "/tmp/test.png");      var readStream=fs.createReadStream(files.upload.path);      var writeStream=fs.createWriteStream("./tmp/test.png");      readStream.pipe(writeStream);      readStream.on(‘end‘,function(){          fs.unlinkSync(files.upload.path);       });

 

      


 

 

Node.js用fs.renameSync報cross-device link not permitted錯誤

聯繫我們

該頁面正文內容均來源於網絡整理,並不代表阿里雲官方的觀點,該頁面所提到的產品和服務也與阿里云無關,如果該頁面內容對您造成了困擾,歡迎寫郵件給我們,收到郵件我們將在5個工作日內處理。

如果您發現本社區中有涉嫌抄襲的內容,歡迎發送郵件至: info-contact@alibabacloud.com 進行舉報並提供相關證據,工作人員會在 5 個工作天內聯絡您,一經查實,本站將立刻刪除涉嫌侵權內容。

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.