Suppose I have the URL to a file. How can I determine the path to the (sub)site (spweb) it is hosted on, using JavaScript.
Here are some examples. Bolded text is what I am looking for:
https://tenant.sharepoint.com/library1/file.jpg
https://tenant.sharepoint.com/sites/site1/library1/file.jpg
https://tenant.sharepoint.com/sites/site1/library1/folder1/file.jpg
https://tenant.sharepoint.com/sites/site1/library1/folder1/folder2/file.jpg
https://tenant.sharepoint.com/sites/site1/subsite1/library1/file.jpg
https://tenant.sharepoint.com/teams/site1/subsite1/library1/folder1/file.jpg
https://tenant.sharepoint.com/teams/site1/subsite1/subsite2/library1/file.jpg