加入收藏 | 设为首页 | 会员中心 | 我要投稿 李大同 (https://www.lidatong.com.cn/)- 科技、建站、经验、云计算、5G、大数据,站长网!
当前位置: 首页 > 百科 > 正文

c# – 通过REST API上传文件时修复Artifactory中的校验和

发布时间:2020-12-15 23:41:05 所属栏目:百科 来源:网络整理
导读:我正在使用下面的代码通过Artifactory的REST API上传文件. 我的问题是,当我通过GUI查看文件时,我得到以下消息: Client did not publish a checksum value. If you trust the uploaded artifact you can accept the actual checksum by clicking the ‘Fix C
我正在使用下面的代码通过Artifactory的REST API上传文件.
我的问题是,当我通过GUI查看文件时,我得到以下消息:

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.

如何修复上传以使此消息消失?

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

我也看到了这个设置:https://www.jfrog.com/confluence/display/RTF20/Handling+Checksums
这可能与我的问题有关吗?

string inFilePath = @"C:tempfile.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;
        }
    }
}

更新

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

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

校验和 – 由Artifactory计算
originalChecksums – 是上传者提供的

当我使用API??时,originalChecksums组是空的,我认为这会呈现上面的消息.

解决方法

我使用 artifactory-client-java库达到同样的问题:-(

所以在digging之后,你似乎需要:

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

对于您的C#示例,正确的解决方案是使用计算的校验和添加标题“X-Checksum-Sha1”.
如链接文档中所述,一个简单的卷曲示例是

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

对于artifactory-client-java用户,简单的解决方法是添加到文档化的上传示例中:

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();

(编辑:李大同)

【声明】本站内容均来自网络,其相关言论仅代表作者个人观点,不代表本站立场。若无意侵犯到您的权利,请及时与联系站长删除相关内容!

    推荐文章
      热点阅读