使用 Sharefile 限制对某些电子邮件的访问

问题描述 投票:0回答:0

在为 Citrix 文件添加的 outlook 上,一个选项显示“谁可以访问此链接”。用户可以为其选择的项目之一是“电子邮件收件人”,这意味着只有电子邮件的收件人才能访问此共享。我试图在我的 C# 代码中复制相同的想法。我怎样才能做到这一点?基本上我想实现插件所做的一切。

我正在使用这个库https://github.com/citrix/ShareFile-NET/

到目前为止,这是我的代码:

public static async Task<string> ShareFilesAsync(ShareFileViewModel model, CancellationToken cancellationToken)
{
    var result = new List<string>();
    s_shareFileClient ??= await LoginAsync(cancellationToken).ConfigureAwait(false);

    var boxUri = s_shareFileClient.Items.GetAlias(ItemAlias.Box);
    var box = await s_shareFileClient.Items.Get(boxUri).ExecuteAsync(cancellationToken);

    var items = new List<Item>();
    foreach (var file in model.Files)
    {
        using var fileStream = System.IO.File.OpenRead(file);
        var uploadRequest = new UploadSpecificationRequest
        {
            FileName = fileStream.Name,
            FileSize = fileStream.Length,
            Details = string.IsNullOrEmpty(model.Subject) ? "Email Attachment" : model.Subject,
            Parent = box.url
        };

        var uploader = s_shareFileClient.GetAsyncFileUploader(uploadRequest, fileStream);
        uploader.OnTransferProgress += (s, e) => model.ReportProgress("Uploading attachments...", e.Progress.BytesTransferred, e.Progress.TotalBytes);
        var uploadResponse = await uploader.UploadAsync(cancellationToken: cancellationToken);
        var fileId = uploadResponse.First().Id;
        var itemUri = s_shareFileClient.Items.GetEntityUriFromId(fileId);
        var item = await s_shareFileClient.Items.Get(itemUri).ExecuteAsync(cancellationToken);
        items.Add(item);
    }

    if(items.Count == 0)
    {
        throw new Exception("Couldn't get files.");
    }

    model.ReportProgress("Sharing links...", 100, 100);
    var share = new Share()
    {
        Items = items,
        MaxDownloads = model.MaxDownloads,
        RequireLogin = model.RequireLogin,
        ExpirationDate = model.Expiry,
        Title = model.Subject,
    };

    var shareRes = await s_shareFileClient.Shares.Create(share).ExecuteAsync(cancellationToken);

    return shareRes.Uri.AbsoluteUri;
}
c# citrix sharefile
© www.soinside.com 2019 - 2024. All rights reserved.