DevOps描述字段图像下载/保存文件



由于我们已经迁移到 Dev Ops,我的应用程序无法下载存储在工作项中的任何字段中的图像。

我有一个图像 URL,该 URL 已通过正则表达式从描述文件中剥离出来。

如果我获取此链接并将其粘贴到浏览器中,则它会返回图像(因此 url 有效(

问题是在下载图像的调用中,我们没有任何身份验证凭据,并且它试图将我返回到登录页面。

我确实使用应用程序中的开发操作服务器进行身份验证,并缓存这些内容。

readonly VssCredentials creds = new VssClientCredentials();

我尝试使用Web客户端进行调用,但您无法将VSScredentuals转换为 system.net 凭据

这以前曾经有效

using (WebClient webClient = new WebClient())
{
byte[] data = webClient.DownloadData(src);
using (MemoryStream mem = new MemoryStream(data))
{
using (var yourImage = Image.FromStream(mem))
{
// If you want it as Png
yourImage.Save(@"c:temppath_to_your_file.png", ImageFormat.Png);
// If you want it as Jpeg
yourImage.Save(@"c:temppath_to_your_file.jpg", ImageFormat.Jpeg);
}
}
}

我也试过使用

using (var client = new TfvcHttpClient(new Uri(src), creds))
{
var itemRequestData = Create(src);
}
private static TfvcItemRequestData Create(string folderPath)
{
return new TfvcItemRequestData
{
IncludeContentMetadata = true,
IncludeLinks = true,
ItemDescriptors =
new[]
{
new TfvcItemDescriptor
{
Path = folderPath,
RecursionLevel = VersionControlRecursionType.Full
}
}
};
}

但是,如何将itemRequestData写入文件呢?

还是我走错了路?

谢谢

试试这个:

using (WebClient webClient = new WebClient())
{
webClient.Headers.Add("Authorization", "Basic " + base64Token);
byte[] data = webClient.DownloadData(src);
// ....      
}

其中base64Token是转换为 base64 的个人访问令牌,开头带有":"。

例如,如果您的令牌是 abcdefg,则需要将:abcdefg转换为 base64 并将其用作授权令牌。

最新更新