我想保存我从服务器上的其他服务器获取的文件,但问题是当我调用createWriteStream时它给了我错误:
没有这样的文件或目录,打开 E:\ pathtoproject \ myproject的\公共\ profile_14454.jpg
这是我的代码,位于E:\pathtoproject\myproject\modules\dowload.js
:
request.head(infos.profile_pic, function(err, res, body) {
const completeFileName = '../public/profile_14454.' + res.headers['content-type'].split('/')[1];
var imageStream = fs.createWriteStream(completeFileName);
imageStream.on('open', function(fd) {
console.log("File open");
request(infos.profile_pic).pipe(imageStream).on('close', function(body) {
consoleLog('Profile pic saved');
console.log('This is the content of body');
console.log(body);
connection.query('UPDATE user set photo=? where id=?', [completeFileName, lastID], function(err, result, fields) {
if (err) {
consoleLog('Error while update the profile pic');
}
});
})
});
});
当我删除目录../public/
并仅保留文件名时
profile_14454.' + res.headers['content-type'].split('/')[1]
,它有效,但文件保存在项目的根目录(E:\pathtoproject\myproject\
)中。
我在做什么有什么问题?如何将文件保存在公共目录下?
我正在使用nodeJS 8.9.4
答案 0 :(得分:0)
我尝试使用我的小代码。
library(wordcloud2)
library(dplyr)
text <- c("anatomical_structure_development",
"nucleic_acid_binding_transcription_factor_activity",
"molecular_function",
"biological_process",
"biosynthetic_process",
"cellular_nitrogen_compound_metabolic_process",
"embryo_development",
"anatomical_structure_formation_involved_in_morphogenesis",
"immune_system_process",
"biosynthetic_process",
"cellular_nitrogen_compound_metabolic_process",
"embryo_development")
# wordcloud2 needs a data.frame with frequencies. This will generate the table from the text.
df <- text %>% data_frame(words = .) %>%
group_by(words) %>%
summarise(freq = n())
wordcloud2(df)
我的代码在此路径中var fs = require("fs");
var data = 'Simply Easy Learning';
// Create a writable stream
var writerStream = fs.createWriteStream('./airo/output.txt');
// Write the data to stream with encoding to be utf8
writerStream.write(data,'UTF8');
// Mark the end of file
writerStream.end();
// Handle stream events --> finish, and error
writerStream.on('finish', function() {
console.log("Write completed.");
});
writerStream.on('error', function(err){
console.log(err.stack);
});
console.log("Program Ended");
现在我想将文件存储在此路径中的E:\syed ayesha\nodejs\nodejs
文件夹中。所以我用一个点来存储。希望这会有所帮助。