[英]Write file to a subdirectory node.js
我正在使用node和express,並且我有一個目錄結構
public
img
css
js
server.js
在server.js中,我有以下代碼用於寫入png文件
fs.writeFile('testfile.png', imageData, function(err){
res.send("file successfully created");
});
這將在根目錄下創建文件,即具有以下目錄結構
public
img
css
js
server.js
testfile.png
如何在img
目錄中創建testfile.png
? 只需使用img/testfile.png
, /img/testfile.png
或/public/img/testfile.png
不work--沒有文件被創建。
幫助贊賞!
你可以這樣做
'./public/img/testfile.png'
或者,您可以像這樣給出相對路徑
__dirname + '/public/img/testfile.png'
還要檢查目錄img
的許可。 可能是未授予寫權限。
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.