diff --git a/APIClient.IntegrationTests/IntegrationTests.cs b/APIClient.IntegrationTests/IntegrationTests.cs
index 6121f05..c872534 100644
--- a/APIClient.IntegrationTests/IntegrationTests.cs
+++ b/APIClient.IntegrationTests/IntegrationTests.cs
@@ -456,7 +456,7 @@ public void CreateDefectWithAttachment()
newDefect.SetAttributeValue(nameAttribute, name);
services.Save(newDefect);
- services.SaveAttachment(file, newDefect, "Test Attachment on " + newDefect.Oid);
+ services.SaveAttachment(file, newDefect, "Test Attachment on " + newDefect.Oid, true);
var query = new Query(newDefect.Oid.Momentless);
query.Selection.Add(attachmentsAttribute);
diff --git a/APIClient/Services/IServices.cs b/APIClient/Services/IServices.cs
index f04166b..59a13b8 100644
--- a/APIClient/Services/IServices.cs
+++ b/APIClient/Services/IServices.cs
@@ -37,6 +37,16 @@ public interface IServices
/// Oid
Oid SaveAttachment(string filePath, Asset asset, string attachmentName);
+ ///
+ /// Saves an attachment to the specified asset.
+ ///
+ /// Path and name of the attachment file.
+ /// Asset to save the attachment to.
+ /// The name of the attachment.
+ /// Sets file name as the file name rather than full path.
+ /// Oid
+ Oid SaveAttachment(string filePath, Asset asset, string attachmentName, bool useFileNameAsFileName);
+
///
/// Saves an embedded image to the specified asset.
///
diff --git a/APIClient/Services/Services.cs b/APIClient/Services/Services.cs
index bc6afd1..5c9e381 100644
--- a/APIClient/Services/Services.cs
+++ b/APIClient/Services/Services.cs
@@ -362,12 +362,24 @@ public string ExecutePassThroughQuery(string query)
}
public Oid SaveAttachment(string filePath, Asset asset, string attachmentName)
+ {
+ return SaveAttachment(filePath, asset, attachmentName, false);
+ }
+
+ public Oid SaveAttachment(string filePath, Asset asset, string attachmentName, bool useFileNameAsFileName)
{
if (string.IsNullOrWhiteSpace(filePath))
throw new ArgumentNullException(nameof(filePath));
if (!File.Exists(filePath))
throw new APIException($"File \"{filePath}\" does not exist.");
+ string fileName;
+
+ if (useFileNameAsFileName)
+ fileName = Path.GetFileName(filePath);
+ else
+ fileName = filePath;
+
var mimeType = MimeType.Resolve(filePath);
var attachmentType = Meta.GetAssetType("Attachment");
var attachmentAssetDef = attachmentType.GetAttributeDefinition("Asset");
@@ -377,7 +389,7 @@ public Oid SaveAttachment(string filePath, Asset asset, string attachmentName)
var attachmentNameAttr = attachmentType.GetAttributeDefinition("Name");
var attachment = New(attachmentType, Oid.Null);
attachment.SetAttributeValue(attachmentNameAttr, attachmentName);
- attachment.SetAttributeValue(attachmentFileName, filePath);
+ attachment.SetAttributeValue(attachmentFileName, fileName);
attachment.SetAttributeValue(attachmentContentType, mimeType);
attachment.SetAttributeValue(attachmentContent, string.Empty);
attachment.SetAttributeValue(attachmentAssetDef, asset.Oid);