1

How to check if a file exists in the 's3' / 'azure' path using node js. fs.stat() or fs.existsSync(path) returns false even if the file exists in the path.

Gimhani
  • 1,318
  • 13
  • 23
Revathi P
  • 51
  • 8
  • 1
    Possible duplicate of [How to determine if object exists AWS S3 Node.JS sdk](https://stackoverflow.com/questions/26726862/how-to-determine-if-object-exists-aws-s3-node-js-sdk) – Artem Arkhipov Sep 05 '18 at 10:52
  • The solution is, where '**request**' is [link](https://www.npmjs.com/package/request), const req = require('request'); req .get('azure_image_path') .on('response', function (res) { if (res.statusCode === 200) { //On Sucsess do something } else { //On Error, handle the error } })` With all other methods it fails, with this method the success and failures results are returned. This worked for me. – Revathi P Sep 07 '18 at 07:24

1 Answers1

1

Import 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
          }
By this way you can check the presence of the file in the CDN path. Provided the authentication credentials are updated in the server.
Revathi P
  • 51
  • 8