直链获取

原理

原链接:https://xxxx-my.sharepoint.com/:x:/g/personal/xx_xx_xx/xxxxxxxxxx

直链:https://xxxx-my.sharepoint.com/personal/xx_xx_xx/_layouts/52/download.aspx?share=xxxxxxxxxx(这一种更有效

或:https://xxxx-my.sharepoint.com/:x:/g/personal/xx_xx_xx/xxxxxxxxxx?download=1(这是重定向跳转至直链

建议使用第一种直链方式

C#实现

//获取xxxx-my.sharepoint.com (域名)
var domainName = Regex.Match(url, @"(?<=://)(.*?)(?=/)").Value;

//获取:x: (文件类型)
var fileType = Regex.Match(url, $"(?<=/{domainName}/:)(.*?)(?=:/)").Value;

//获取xx_xx_xx (组织名_用户名)
var organizationName = Regex.Match(url, @"(?<=/personal/)(.*?)(?=/)").Value;

//获取xxxxxxxxxx (文件ID)
var fileId = Regex.Match(url, $"(?<=/{organizationName}/).+").Value;

string newUrl = "";

if (string.IsNullOrEmpty(domainName) || string.IsNullOrEmpty(fileType) || string.IsNullOrEmpty(organizationName) || string.IsNullOrEmpty(fileId))
{
    newUrl = "请输入正确链接";
}
else if (fileType == "f")
{
    newUrl = "抱歉,你所输入链接分享的是文件夹,直链生成仅对单文件有效。";
}
else
{
    newUrl = $"https://{domainName}/personal/{organizationName}/_layouts/52/download.aspx?share={fileId}";
}

云函数

使用微软云函数,通过Get方法或Post方法进行调用

Get: https://getonedrivelink.azurewebsites.net/api/GetLink?url={url}
Post: https://getonedrivelink.azurewebsites.net/api/GetLink Body:{"url":{url}}

在线调用

https://onedrivelink.ccrui.cn/

在线调用

Last modification:October 9, 2022
本文作者:
文章标题:OneDrive for Business直链提取
本文地址:https://ccrui.cn/archives/onedrive-for-business-zhi-lian-ti-qu.html
版权说明:若无注明,本文皆个人的辣鸡小站原创,转载请保留文章出处。
如果觉得我的文章对你有用,请随意赞赏