开发者

distinguish html link and image link like Facebook attach in .NET

开发者 https://www.devze.com 2023-03-20 21:59 出处:网络
like facebook attach link, when i share a link -> facebook fetch the html page when i share a image link -> facebook fetch the image

like facebook attach link,

when i share a link -> facebook fetch the html page

when i share a image link -> facebook fetch the image

so at server side (.NET, C#), how can i distin开发者_运维百科guish a html link or image link

any help?


You could try a couple things:

  • Do a regex on the URL and check for a file extension. E.g. \.(png|jpg|gif|bmp)$
  • Actually retrieve the document, and check the mime type

Also, check answers to this question:

Regex to check if valid URL that ends in .jpg, .png, or .gif

The most recent answer there mentions a library called FastImage.

0

精彩评论

暂无评论...
验证码 换一张
取 消

关注公众号