通过REST API上传文件时,修正Artifactory中的校验和 [英] Fix checksum in Artifactory when uploading file through REST API

查看:438
本文介绍了通过REST API上传文件时,修正Artifactory中的校验和的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在使用以下代码通过Artifactory的REST API上传文件. 我的问题是,当我通过GUI查看文件时,收到以下消息:

I'm using the code below to upload a file through Artifactory's REST API. My problem is that when I view the file through the GUI I get this message:

客户端未发布校验和值.如果您相信上传的 您可以通过单击修复"来接受实际的校验和 校验和"按钮.

Client did not publish a checksum value. If you trust the uploaded artifact you can accept the actual checksum by clicking the 'Fix Checksum' button.

如何修复上传内容,以便此消息消失?

How do I fix the upload so that this message disappears?

如果我通过GUI上传文件,则不提供校验和值,那么为什么在使用API​​时必须这样做?使用API​​修复校验和时,我可以调用额外的功能吗?

If I upload the file through the GUI I'm not supplying checksum values so why do I have to do it when I use the API? Is there an extra function I can call when using the API to fix the checksums?

我还看到了以下设置: https://www.jfrog.com/融合/显示/RTF20/处理+校验和 这与我的问题有关系吗?

I also saw this setting: https://www.jfrog.com/confluence/display/RTF20/Handling+Checksums Could this have anything to do with my problem?

string inFilePath = @"C:\temp\file.ext";
string inUrl = @"domain.com/repoKey/";
string username = "username";
string apiKey = "apikey";

using (HttpClient client = new HttpClient())
{
    client.DefaultRequestHeaders.Authorization =
        new AuthenticationHeaderValue("Basic", Convert.ToBase64String(Encoding.ASCII.GetBytes(username+":"+apiKey)));

    using (var stream = File.OpenRead(inFilePath))
    {
        var response = client.PutAsync(inUrl + stream.Name, new StreamContent(stream));

        using (HttpContent content = response.Result.Content)
        {
            string data = content.ReadAsStringAsync().Result;
        }
    }
}

更新

共有三种类型的校验和和两组校验和组.

There are three types of checksums and two sets of checksum groups.

"checksums" : {
  "sha1" : "94332c090bdcdd87bd86426c224bcc7dc1c5f784",
  "md5" : "dcada413214a5bd7164c6961863f5111",
  "sha256" : "049c671f48e94c1ad25500f64e4879312cae70f489edc21313334b3f77b631e6"
},
"originalChecksums" : {
  "sha1" : "94332c090bdcdd87bd86426c224bcc7dc1c5f784",
  "md5" : "dcada413214a5bd7164c6961863f5111"
}

checksums-由Artifactory
计算 originalChecksums-由上传者提供的

checksums - are calculated by Artifactory
originalChecksums - are the ones supplied by the uploader

当我使用API​​时,originalChecksums组为空,我认为是上面的消息.

When I use the API the originalChecksums group is empty which I think renders the message above.

推荐答案

我正在使用所以在挖掘,看来您需要:

  • 计算客户端(sha1)的校验和
  • 在PUT请求上提供每个校验和作为HTTP标头

对于您的C#示例,正确的解决方案是将标头"X-Checksum-Sha1" 与计算出的校验和相加. 如链接文档中所述,一个简单的curl示例是

For your C# example, the correct solution is to add a header "X-Checksum-Sha1" with the calculated checksum. As explained in the link documentation, a simple curl example is

curl -uadmin:password -T file.jar -H "X-Checksum-Sha1:c9a355147857198da3bdb3f24c4e90bd98a61e8b""http://localhost:8081/artifactory/libs-release-local/file.jar" -i

对于articleory-client-java用户,简单的解决方法是将其添加到已记录的上载示例中:

For artifactory-client-java users, the easy fix is to add to the documented upload example:

java.io.File file = new java.io.File("fileToUpload.txt");
File result = artifactory.repository("RepoName").upload("path/to/newName.txt", file).doUpload();

另一个中介调用: bySha1Checksum():

java.io.File file = new java.io.File("fileToUpload.txt");
File result = artifactory.repository("RepoName").upload("path/to/newName.txt", file).bySha1Checksum().doUpload();

这篇关于通过REST API上传文件时,修正Artifactory中的校验和的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆