Skip to content

Commit

Permalink
Add support for Dynamic Folders parameters in Explicit Upload API
Browse files Browse the repository at this point in the history
  • Loading branch information
const-cloudinary authored Jun 30, 2022
1 parent 858c1b9 commit b637e9d
Show file tree
Hide file tree
Showing 2 changed files with 48 additions and 1 deletion.
21 changes: 20 additions & 1 deletion CloudinaryDotNet.Tests/Parameters/ParametersTest.cs
Original file line number Diff line number Diff line change
Expand Up @@ -175,7 +175,7 @@ public void TestImageUploadParamsDictionary()
}

[Test]
public void TestUploadFolderDecouplingParamsCheck()
public void TestUploadDynamicFoldersParamsCheck()
{
var parameters = new ImageUploadParams
{
Expand All @@ -197,6 +197,25 @@ public void TestUploadFolderDecouplingParamsCheck()
Assert.AreEqual("folder", dictionary["folder"]);
}

[Test]
public void TestExplicitDynamicFoldersParamsCheck()
{
var parameters = new ExplicitParams("test_id")
{
PublicIdPrefix = "fd_public_id_prefix",
DisplayName = "test",
UseFilenameAsDisplayName = true,
AssetFolder = "asset_folder"
};

var dictionary = parameters.ToParamsDictionary();

Assert.AreEqual("fd_public_id_prefix", dictionary["public_id_prefix"]);
Assert.AreEqual("test", dictionary["display_name"]);
Assert.AreEqual("true", dictionary["use_filename_as_display_name"]);
Assert.AreEqual("asset_folder", dictionary["asset_folder"]);
}

[Test]
public void TestExplicitParamsDictionary()
{
Expand Down
28 changes: 28 additions & 0 deletions CloudinaryDotNet/Actions/AssetsUpload/ExplicitParams.cs
Original file line number Diff line number Diff line change
Expand Up @@ -68,6 +68,12 @@ public ExplicitParams(string publicId)
/// </summary>
public string PublicId { get; set; }

/// <summary>
/// Gets or sets the identifier that is used to provide context and to improve the SEO of an assets filename in the delivery URL.
/// It does not impact the location where the asset is stored.
/// </summary>
public string PublicIdPrefix { get; set; }

/// <summary>
/// Gets or sets an HTTP header or a list of headers lines for returning as response HTTP headers when delivering the
/// uploaded image to your users. Supported headers: 'Link', 'X-Robots-Tag'.
Expand All @@ -81,6 +87,24 @@ public ExplicitParams(string publicId)
/// </summary>
public string Tags { get; set; }

/// <summary>
/// Gets or sets the name that is displayed for the asset in the Media Library.
/// This value does not impact the asset’s Public ID.
/// </summary>
public string DisplayName { get; set; }

/// <summary>
/// Gets or sets whether to automatically assign the filename of the uploaded asset as the asset’s display name in the Media Library.
/// Relevant only if <see cref="DisplayName"/> is not passed.
/// </summary>
public bool? UseFilenameAsDisplayName { get; set; }

/// <summary>
/// Gets or sets the folder where the asset is stored in the Media Library.
/// This value does not impact the asset’s Public ID.
/// </summary>
public string AssetFolder { get; set; }

/// <summary>
/// Gets or sets the coordinates of faces contained in an uploaded image and overrides the automatically detected
/// faces.
Expand Down Expand Up @@ -233,6 +257,7 @@ public override SortedDictionary<string, object> ToParamsDictionary()
var dict = base.ToParamsDictionary();

AddParam(dict, "public_id", PublicId);
AddParam(dict, "public_id_prefix", PublicIdPrefix);
AddParam(dict, "tags", Tags);
AddParam(dict, "type", Type);
AddParam(dict, "ocr", Ocr);
Expand All @@ -248,6 +273,9 @@ public override SortedDictionary<string, object> ToParamsDictionary()
AddParam(dict, "quality_override", QualityOverride);
AddParam(dict, "moderation", Moderation);
AddParam(dict, "accessibility_analysis", AccessibilityAnalysis);
AddParam(dict, "display_name", DisplayName);
AddParam(dict, "use_filename_as_display_name", UseFilenameAsDisplayName);
AddParam(dict, "asset_folder", AssetFolder);

if (ResourceType == ResourceType.Image)
{
Expand Down

0 comments on commit b637e9d

Please sign in to comment.