简体   繁体   English

设置文件路径时在NodejS中出错

[英]Getting error in NodejS when setting the file path

Here what i am doing ,I am getting the file path from这是我在做什么,我正在从中获取文件路径

 var url = JSON.stringify(req.body.path); 

which giving me the correct path but when i am using the passing the url inside the below chunk of code这给了我正确的路径,但是当我在下面的代码块中使用传递url

 fs.createReadStream(url).
    pipe(bucket.openUploadStream('test.apk')).
    on('error', function(error) {
      assert.ifError(error);
    }).
    on('finish', function() {
      console.log('done!');
      res.send("Uploaded Sucessfully..")
      process.exit(0);
    });

};

I am getting below error我得到以下错误

Error: ENOENT: no such file or directory, open 'E:\\SomeServer\\"..\\apks\\testappV1.0.0.apk"'错误:ENOENT:没有这样的文件或目录,打开'E:\\SomeServer\\"..\\apks\\testappV1.0.0.apk"'
at Error (native)在错误(本机)

but if i am hard coding但如果我是硬编码

var url1 = '../apks/testappV1.0.0.apk';

the url1 is working perfdect with the above code why url not working i think i am doing some silly mistake not able to find , Can you please point out what i am doing wrong here.url1正在perfdect与为什么上面的代码url不工作我觉得我做了一些愚蠢的错误无法找到,你可以请大家指出我做错了这里。

No need to stringify the path.No JSON.stringify.无需字符串化路径。没有 JSON.stringify。 req.body.path is already a string. req.body.path 已经是一个字符串。

var url = req.body.path; 

fs.createReadStream(url).
    pipe(bucket.openUploadStream('test.apk')).
    on('error', function(error) {
      assert.ifError(error);
    }).
    on('finish', function() {
      console.log('done!');
      res.send("Uploaded Sucessfully..")
      process.exit(0);
    });

};

Hope this helps.希望这可以帮助。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM