From 3429c0aad9f6a3b5e5039e4e757c698f60f49fa9 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E6=9D=8E=E5=BB=BA=E8=BE=89?= Date: Mon, 24 Jan 2022 14:56:39 +0800 Subject: [PATCH] fix 403 error upload file on seafile server 8.0.x --- .gitignore | 1 + SeafClient/Requests/Files/GetUploadLinkRequest.cs | 7 +++++-- SeafClient/SeafSession.cs | 2 +- 3 files changed, 7 insertions(+), 3 deletions(-) diff --git a/.gitignore b/.gitignore index 45c6783..a3f51bb 100644 --- a/.gitignore +++ b/.gitignore @@ -182,3 +182,4 @@ UpgradeLog*.htm # Microsoft Fakes FakesAssemblies/ /SeafClient.v2.ncrunchproject +/.vs diff --git a/SeafClient/Requests/Files/GetUploadLinkRequest.cs b/SeafClient/Requests/Files/GetUploadLinkRequest.cs index 4bd9718..cdfc814 100644 --- a/SeafClient/Requests/Files/GetUploadLinkRequest.cs +++ b/SeafClient/Requests/Files/GetUploadLinkRequest.cs @@ -13,15 +13,18 @@ public class GetUploadLinkRequest : SessionRequest { public String LibraryId { get; set; } + public string ParentDir { get; set; } + public override string CommandUri { - get { return String.Format("api2/repos/{0}/upload-link/", LibraryId); } + get { return $"api2/repos/{LibraryId}/upload-link/?p={ParentDir}"; } } - public GetUploadLinkRequest(string authToken, string libraryId) + public GetUploadLinkRequest(string authToken, string libraryId, string parentDir = "/") : base(authToken) { LibraryId = libraryId; + ParentDir = parentDir; } public override SeafError GetSeafError(System.Net.Http.HttpResponseMessage msg) diff --git a/SeafClient/SeafSession.cs b/SeafClient/SeafSession.cs index 0932ac7..215e10f 100644 --- a/SeafClient/SeafSession.cs +++ b/SeafClient/SeafSession.cs @@ -900,7 +900,7 @@ public async Task UploadSingle(SeafLibrary library, string targetDirectory public async Task UploadSingle(string libraryId, string targetDirectory, string targetFilename, Stream fileContent, Action progressCallback = null) { // to upload files we need to get an upload link first - var req = new GetUploadLinkRequest(AuthToken, libraryId); + var req = new GetUploadLinkRequest(AuthToken, libraryId, targetDirectory); var uploadLink = await _webConnection.SendRequestAsync(ServerUri, req); var uploadRequest = new UploadFilesRequest(AuthToken, uploadLink, targetDirectory, targetFilename, fileContent, progressCallback);