简体   繁体   中英

how to check the aws s3 url is valid or not

I need to check the AWS s3 URL is valid or not using Nodejs, I need only the status code not all the data of the file exa:- https://test.s3.us-east-2.amazonaws.com/occupancy.csv , I applied request method but it takes all the data from the file..second method AWS s3.headObject but it only checks the bucket name exist or not tell me is there any method who give the status code that this URL has existed or not

You can simply do an HTTP head request to check whether the url exist.

var request = require("request");

var options = {
  method: 'HEAD',
  url: 'https://test.s3.us-east-2.amazonaws.com/occupancy.csv',
};

request(options, function (error, response, body) {
  if (error) throw new Error(error);

  console.log(response.statusCode);
});

Reference: Getting HTTP headers with node.js

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

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