Skip to content

Commit 0c14953

Browse files
committed
feat: new file not found error for UploadPackage()
1 parent c424601 commit 0c14953

File tree

2 files changed

+19
-10
lines changed

2 files changed

+19
-10
lines changed

Fossology.Rest.Dotnet/ErrorCode.cs

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
// ---------------------------------------------------------------------------
22
// <copyright file="ErrorCode.cs" company="Tethys">
3-
// Copyright (C) 2019-2020 T. Graf
3+
// Copyright (C) 2019-2022 T. Graf
44
// </copyright>
55
//
66
// Licensed under the MIT License.
@@ -38,5 +38,10 @@ public enum ErrorCode
3838
/// A REST API error has happened.
3939
/// </summary>
4040
RestApiError = 3,
41+
42+
/// <summary>
43+
/// File to upload not found.
44+
/// </summary>
45+
FileNotFound = 4,
4146
} // ErrorCode
4247
}

Fossology.Rest.Dotnet/FossologyClientUpload.cs

Lines changed: 13 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -43,13 +43,10 @@ public partial class FossologyClient
4343
/// <param name="description">The description.</param>
4444
/// <param name="accessLevel">The access level.</param>
4545
/// <param name="ignoreScm">if set to <c>true</c> ignore SCM files.</param>
46-
/// <returns>
47-
/// An <see cref="Result" /> object.
48-
/// </returns>
49-
/// <remarks>
50-
/// The message property of the result contains the upload id
51-
/// which is needed for further operations.
52-
/// </remarks>
46+
/// <param name="applyGlobal">if set to <c>true</c> apply global decisions.</param>
47+
/// <returns>An <see cref="Result" /> object.</returns>
48+
/// <remarks>The message property of the result contains the upload id
49+
/// which is needed for further operations.</remarks>
5350
public Result UploadPackage(
5451
string fileName,
5552
int folderId,
@@ -58,10 +55,16 @@ public Result UploadPackage(
5855
Action<float> uploadProgress = null,
5956
string description = "",
6057
string accessLevel = "public",
61-
bool ignoreScm = true)
58+
bool ignoreScm = true,
59+
bool applyGlobal = false)
6260
{
6361
Log.Debug($"Uploading package {fileName} to folder {folderId}...");
6462

63+
if (!File.Exists(fileName))
64+
{
65+
throw new FossologyApiException(ErrorCode.FileNotFound, fileName);
66+
} // if
67+
6568
var request = new RestRequest(this.Url + "/uploads", Method.POST);
6669
request.RequestFormat = DataFormat.Json;
6770
request.AddHeader("folderId", folderId.ToString());
@@ -70,13 +73,14 @@ public Result UploadPackage(
7073
request.AddHeader("public", accessLevel);
7174
request.AddHeader("ignoreScm", ignoreScm.ToString());
7275
request.AddHeader("Content-Type", "multipart/form-data");
76+
request.AddHeader("applyGlobal", applyGlobal.ToString());
7377

7478
var fi = new FileInfo(fileName);
7579
var item = new FileParameter
7680
{
7781
Name = "fileInput",
7882
ContentLength = fi.Length,
79-
FileName = fileName,
83+
FileName = fi.Name,
8084
ContentType = "application/octet-stream",
8185
};
8286
item.Writer = stream =>

0 commit comments

Comments
 (0)