Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
9 changes: 8 additions & 1 deletion Samples/SeafConsole/SeafConsole.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@
<AppDesignerFolder>Properties</AppDesignerFolder>
<RootNamespace>SeafConsole</RootNamespace>
<AssemblyName>SeafConsole</AssemblyName>
<TargetFrameworkVersion>v4.5.2</TargetFrameworkVersion>
<TargetFrameworkVersion>v4.8</TargetFrameworkVersion>
<FileAlignment>512</FileAlignment>
<AutoGenerateBindingRedirects>true</AutoGenerateBindingRedirects>
</PropertyGroup>
Expand All @@ -33,6 +33,12 @@
<WarningLevel>4</WarningLevel>
</PropertyGroup>
<ItemGroup>
<Reference Include="Newtonsoft.Json, Version=13.0.0.0, Culture=neutral, PublicKeyToken=30ad4fe6b2a6aeed, processorArchitecture=MSIL">
<HintPath>..\..\packages\Newtonsoft.Json.13.0.3\lib\net45\Newtonsoft.Json.dll</HintPath>
</Reference>
<Reference Include="Newtonsoft.Json.Bson, Version=1.0.0.0, Culture=neutral, PublicKeyToken=30ad4fe6b2a6aeed, processorArchitecture=MSIL">
<HintPath>..\..\packages\Newtonsoft.Json.Bson.1.0.2\lib\net45\Newtonsoft.Json.Bson.dll</HintPath>
</Reference>
<Reference Include="System" />
<Reference Include="System.Core" />
<Reference Include="System.Xml.Linq" />
Expand All @@ -50,6 +56,7 @@
</ItemGroup>
<ItemGroup>
<None Include="App.config" />
<None Include="packages.config" />
</ItemGroup>
<ItemGroup>
<ProjectReference Include="..\..\SeafClient\SeafClient.csproj">
Expand Down
4 changes: 2 additions & 2 deletions SeafClient.Tests/SeafClient.Tests.csproj
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
<Project Sdk="Microsoft.NET.Sdk">

<PropertyGroup>
<TargetFramework>netcoreapp2.0</TargetFramework>
<TargetFramework>net8.0</TargetFramework>

<IsPackable>false</IsPackable>
</PropertyGroup>
Expand All @@ -12,7 +12,7 @@
<PackageReference Include="MSTest.TestAdapter" Version="2.0.0" />
<PackageReference Include="MSTest.TestFramework" Version="2.0.0" />
<PackageReference Include="coverlet.collector" Version="1.2.0" />
<PackageReference Include="Newtonsoft.Json" Version="12.0.3" />
<PackageReference Include="Newtonsoft.Json" Version="13.0.3" />
</ItemGroup>

<ItemGroup>
Expand Down
30 changes: 22 additions & 8 deletions SeafClient/Requests/Files/UploadFilesRequest.cs
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,8 @@ public class UploadFilesRequest : SessionRequest<bool>
public string TargetDirectory { get; set; }

List<UploadFileInfo> files = new List<UploadFileInfo>();

public bool Replace { get; set; }

public List<UploadFileInfo> Files
{
Expand Down Expand Up @@ -51,8 +53,8 @@ public override HttpAccessMethod HttpAccessMethod
/// <param name="filename"></param>
/// <param name="fileContent"></param>
/// <param name="progressCallback"></param>
public UploadFilesRequest(string authToken, string uploadUri, string targetDirectory, string filename, Stream fileContent, Action<float> progressCallback)
: this(authToken, uploadUri, targetDirectory, progressCallback, new UploadFileInfo(filename, fileContent))
public UploadFilesRequest(string authToken, string uploadUri, string targetDirectory, string filename, Stream fileContent, Action<float> progressCallback, bool replace)
: this(authToken, uploadUri, targetDirectory, replace, progressCallback, new UploadFileInfo(filename, fileContent))
{
// --
}
Expand All @@ -65,12 +67,13 @@ public UploadFilesRequest(string authToken, string uploadUri, string targetDirec
/// <param name="filename"></param>
/// <param name="fileContent"></param>
/// <param name="progressCallback"></param>
public UploadFilesRequest(string authToken, string uploadUri, string targetDirectory, Action<float> progressCallback, params UploadFileInfo[] uploadFiles)
public UploadFilesRequest(string authToken, string uploadUri, string targetDirectory, bool replace, Action<float> progressCallback, params UploadFileInfo[] uploadFiles)
: base(authToken)
{
UploadUri = uploadUri;
UploadProgress = progressCallback;
TargetDirectory = targetDirectory;
Replace = replace;

files.AddRange(uploadFiles);
}
Expand Down Expand Up @@ -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))
Expand All @@ -139,6 +152,7 @@ public override HttpRequestMessage GetCustomizedRequest(Uri serverUri)

return request;
}

}

/// <summary>
Expand Down
2 changes: 1 addition & 1 deletion SeafClient/SeafClient.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@
</PropertyGroup>

<ItemGroup>
<PackageReference Include="Newtonsoft.Json" Version="12.0.3" />
<PackageReference Include="Newtonsoft.Json" Version="13.0.3" />
</ItemGroup>

<ItemGroup>
Expand Down
12 changes: 7 additions & 5 deletions SeafClient/SeafSession.cs
Original file line number Diff line number Diff line change
Expand Up @@ -877,13 +877,14 @@ public string GetThumbnailUrl(string libraryId, string path, int size)
/// <param name="library">The library the file should be uploaded to</param>
/// <param name="targetDirectory">The directory the file should be uploaded to</param>
/// <param name="targetFilename">The name of the file</param>
/// <param name="replace">If true, the files will be replaced if it already exists</param>
/// <param name="fileContent">The new content of the file</param>
/// <param name="progressCallback">Optional progress callback (will report percentage of upload)</param>
public async Task<bool> UploadSingle(SeafLibrary library, string targetDirectory, string targetFilename, Stream fileContent, Action<float> progressCallback = null)
public async Task<bool> UploadSingle(SeafLibrary library, string targetDirectory, string targetFilename, bool replace, Stream fileContent, Action<float> 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);
}

/// <summary>
Expand All @@ -895,15 +896,16 @@ public async Task<bool> UploadSingle(SeafLibrary library, string targetDirectory
/// <param name="libraryId">The id of the library the file should be uploaded to</param>
/// <param name="targetDirectory">The directory the file should be uploaded to</param>
/// <param name="targetFilename">The name of the file</param>
/// <param name="replace">If true, the files will be replaced if it already exists</param>
/// <param name="fileContent">The new content of the file</param>
/// <param name="progressCallback">Optional progress callback (will report percentage of upload)</param>
public async Task<bool> UploadSingle(string libraryId, string targetDirectory, string targetFilename, Stream fileContent, Action<float> progressCallback = null)
public async Task<bool> UploadSingle(string libraryId, string targetDirectory, string targetFilename, bool replace, Stream fileContent, Action<float> 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);
}

Expand Down