diff --git a/Samples/SeafConsole/SeafConsole.csproj b/Samples/SeafConsole/SeafConsole.csproj
index 2f3ecab..fe57277 100644
--- a/Samples/SeafConsole/SeafConsole.csproj
+++ b/Samples/SeafConsole/SeafConsole.csproj
@@ -9,7 +9,7 @@
Properties
SeafConsole
SeafConsole
- v4.5.2
+ v4.8
512
true
@@ -33,6 +33,12 @@
4
+
+ ..\..\packages\Newtonsoft.Json.13.0.3\lib\net45\Newtonsoft.Json.dll
+
+
+ ..\..\packages\Newtonsoft.Json.Bson.1.0.2\lib\net45\Newtonsoft.Json.Bson.dll
+
@@ -50,6 +56,7 @@
+
diff --git a/SeafClient.Tests/SeafClient.Tests.csproj b/SeafClient.Tests/SeafClient.Tests.csproj
index 7c02a98..bc2eb07 100644
--- a/SeafClient.Tests/SeafClient.Tests.csproj
+++ b/SeafClient.Tests/SeafClient.Tests.csproj
@@ -1,7 +1,7 @@
- netcoreapp2.0
+ net8.0
false
@@ -12,7 +12,7 @@
-
+
diff --git a/SeafClient/Requests/Files/UploadFilesRequest.cs b/SeafClient/Requests/Files/UploadFilesRequest.cs
index 58eb61c..ba742f7 100644
--- a/SeafClient/Requests/Files/UploadFilesRequest.cs
+++ b/SeafClient/Requests/Files/UploadFilesRequest.cs
@@ -24,6 +24,8 @@ public class UploadFilesRequest : SessionRequest
public string TargetDirectory { get; set; }
List files = new List();
+
+ public bool Replace { get; set; }
public List Files
{
@@ -51,8 +53,8 @@ public override HttpAccessMethod HttpAccessMethod
///
///
///
- public UploadFilesRequest(string authToken, string uploadUri, string targetDirectory, string filename, Stream fileContent, Action progressCallback)
- : this(authToken, uploadUri, targetDirectory, progressCallback, new UploadFileInfo(filename, fileContent))
+ public UploadFilesRequest(string authToken, string uploadUri, string targetDirectory, string filename, Stream fileContent, Action progressCallback, bool replace)
+ : this(authToken, uploadUri, targetDirectory, replace, progressCallback, new UploadFileInfo(filename, fileContent))
{
// --
}
@@ -65,12 +67,13 @@ public UploadFilesRequest(string authToken, string uploadUri, string targetDirec
///
///
///
- public UploadFilesRequest(string authToken, string uploadUri, string targetDirectory, Action progressCallback, params UploadFileInfo[] uploadFiles)
+ public UploadFilesRequest(string authToken, string uploadUri, string targetDirectory, bool replace, Action progressCallback, params UploadFileInfo[] uploadFiles)
: base(authToken)
{
UploadUri = uploadUri;
UploadProgress = progressCallback;
TargetDirectory = targetDirectory;
+ Replace = replace;
files.AddRange(uploadFiles);
}
@@ -106,17 +109,27 @@ public override HttpRequestMessage GetCustomizedRequest(Uri serverUri)
content.Add(fileContent);
}
-
- // the parent dir to upload the file to
+
string tDir = TargetDirectory;
- if (!tDir.StartsWith("/"))
- tDir = "/" + tDir;
+ if (tDir.StartsWith("/"))
+ tDir = tDir.Substring(1);
- var dirContent = new StringContent(tDir, Encoding.UTF8);
+ var dirContent = new StringContent("/", Encoding.UTF8);
dirContent.Headers.ContentType = null;
dirContent.Headers.TryAddWithoutValidation("Content-Disposition", @"form-data; name=""parent_dir""");
content.Add(dirContent);
+ var relativePathContent = new StringContent(tDir);
+ relativePathContent.Headers.ContentType = null;
+ relativePathContent.Headers.TryAddWithoutValidation("Content-Disposition", @"form-data; name=""relative_path""");
+ content.Add(relativePathContent);
+
+ var replaceContent = new StringContent(Replace ? "1" : "0");
+ replaceContent.Headers.ContentType = null;
+ replaceContent.Headers.TryAddWithoutValidation("Content-Disposition", @"form-data; name=""replace""");
+ content.Add(replaceContent);
+
+
// transmit the content length
long conLen;
if (!content.ComputeLength(out conLen))
@@ -139,6 +152,7 @@ public override HttpRequestMessage GetCustomizedRequest(Uri serverUri)
return request;
}
+
}
///
diff --git a/SeafClient/SeafClient.csproj b/SeafClient/SeafClient.csproj
index f2b6450..c367aac 100644
--- a/SeafClient/SeafClient.csproj
+++ b/SeafClient/SeafClient.csproj
@@ -12,7 +12,7 @@
-
+
diff --git a/SeafClient/SeafSession.cs b/SeafClient/SeafSession.cs
index 0932ac7..6d3aed2 100644
--- a/SeafClient/SeafSession.cs
+++ b/SeafClient/SeafSession.cs
@@ -877,13 +877,14 @@ public string GetThumbnailUrl(string libraryId, string path, int size)
/// The library the file should be uploaded to
/// The directory the file should be uploaded to
/// The name of the file
+ /// If true, the files will be replaced if it already exists
/// The new content of the file
/// Optional progress callback (will report percentage of upload)
- public async Task UploadSingle(SeafLibrary library, string targetDirectory, string targetFilename, Stream fileContent, Action progressCallback = null)
+ public async Task UploadSingle(SeafLibrary library, string targetDirectory, string targetFilename, bool replace, Stream fileContent, Action progressCallback = null)
{
library.ThrowOnNull(nameof(library));
- return await UploadSingle(library.Id, targetDirectory, targetFilename, fileContent, progressCallback);
+ return await UploadSingle(library.Id, targetDirectory, targetFilename, replace, fileContent, progressCallback);
}
///
@@ -895,15 +896,16 @@ public async Task UploadSingle(SeafLibrary library, string targetDirectory
/// The id of the library the file should be uploaded to
/// The directory the file should be uploaded to
/// The name of the file
+ /// If true, the files will be replaced if it already exists
/// The new content of the file
/// Optional progress callback (will report percentage of upload)
- public async Task UploadSingle(string libraryId, string targetDirectory, string targetFilename, Stream fileContent, Action progressCallback = null)
+ public async Task UploadSingle(string libraryId, string targetDirectory, string targetFilename, bool replace, Stream fileContent, Action progressCallback = null)
{
// to upload files we need to get an upload link first
var req = new GetUploadLinkRequest(AuthToken, libraryId);
var uploadLink = await _webConnection.SendRequestAsync(ServerUri, req);
-
- var uploadRequest = new UploadFilesRequest(AuthToken, uploadLink, targetDirectory, targetFilename, fileContent, progressCallback);
+
+ var uploadRequest = new UploadFilesRequest(AuthToken, uploadLink, targetDirectory, targetFilename, fileContent, progressCallback, replace);
return await _webConnection.SendRequestAsync(ServerUri, uploadRequest);
}