【问题标题】:How to check if a file exists in the 's3' / 'azure' path using node js如何使用节点 js 检查“s3”/“azure”路径中是否存在文件
【发布时间】:2019-02-10 11:47:54
【问题描述】:

如何使用 node js 检查“s3”/“azure”路径中是否存在文件。 fs.stat()fs.existsSync(path) 即使文件存在于路径中也会返回 false。

【问题讨论】:

  • 解决方法是,'request' 是link, const req = require('request'); req .get('azure_image_path') .on('response', function (res) { if (res.statusCode === 200) { //成功做某事 } else { //出错,处理错误 } } )` 使用所有其他方法失败,使用此方法返回成功和失败结果。这对我有用。

标签: javascript node.js


【解决方案1】:

导入https://www.npmjs.com/package/@types/request

const request = require('request'); 
request
        .get(cdn_image_path)
        .on('response', function (res) {
          if (res.statusCode === 200) {
            //Do something
          } else {
            //Do something if file is absent
          }
通过这种方式,您可以检查 CDN 路径中的文件是否存在。前提是在服务器中更新了身份验证凭据。

【讨论】:

    猜你喜欢
    • 2019-03-16
    • 2012-06-08
    • 2012-02-09
    • 2022-12-06
    • 2016-04-29
    • 1970-01-01
    • 2018-01-23
    • 2019-10-15
    • 1970-01-01
    相关资源
    最近更新 更多