我使用Dropbox.Net API v2.0将文档上传到Dropbox:
private async Task Upload(DropboxClient dbx, string localPath, string remotePath)
{
using (var fileStream = File.Open(localPath, FileMode.Open))
{
var s = await dbx.Files.UploadAsync(remotePath, body: fileStream);
}
}
如何获取上传文档的共享链接?
我试过了:
await dbx.Sharing.GetSharedLinkFileAsync(remotePath);
但是出现了以下错误:
<Message>An error has occurred.</Message>
<ExceptionMessage>shared_link_not_found/.</ExceptionMessage>
我有什么不对,但不确定是什么,有什么想法吗?
答案 0 :(得分:2)
我找到了答案:
var result = await dbx.Sharing.CreateSharedLinkWithSettingsAsync(remotePath);
var url = result.Url;
完美无缺。
答案 1 :(得分:2)
var link = dbx.Sharing.ListSharedLinksAsync(FolderName + "/" + UploadFileName);
if (link.Result.Links.Count == 0)
{
var result =
dbx.Sharing.CreateSharedLinkWithSettingsAsync(FolderName+"/"+UploadFileName);
string url = result.Result.Url;
}
else
{
string url = link.Result.Links[0].Url;
URL = url;
}
这样,您可以检查现有链接并根据需要添加新链接。