Skip to content
9 changes: 8 additions & 1 deletion Src/Notion.Client/Models/File/FIleInput/ExternalFileInput.cs
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
using Newtonsoft.Json;
using System.Collections.Generic;
using Newtonsoft.Json;

namespace Notion.Client
{
Expand All @@ -7,6 +8,12 @@ public class ExternalFileInput : IFileObjectInput
[JsonProperty("external")]
public Data External { get; set; }

[JsonProperty("name")]
public string Name { get; set; }

[JsonProperty("caption")]
public IEnumerable<RichTextBaseInput> Caption { get; set; }

public class Data
{
[JsonProperty("url")]
Expand Down
10 changes: 9 additions & 1 deletion Src/Notion.Client/Models/File/FIleInput/IFileObjectInput.cs
Original file line number Diff line number Diff line change
@@ -1,6 +1,14 @@
namespace Notion.Client
using System.Collections.Generic;
using Newtonsoft.Json;

namespace Notion.Client
{
public interface IFileObjectInput
{
[JsonProperty("name")]
public string Name { get; set; }

[JsonProperty("caption")]
public IEnumerable<RichTextBaseInput> Caption { get; set; }
}
}
7 changes: 7 additions & 0 deletions Src/Notion.Client/Models/File/FIleInput/UploadedFileInput.cs
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
using System;
using System.Collections.Generic;
using Newtonsoft.Json;

namespace Notion.Client
Expand All @@ -8,6 +9,12 @@ public class UploadedFileInput : IFileObjectInput
[JsonProperty("file")]
public Data File { get; set; }

[JsonProperty("name")]
public string Name { get; set; }

[JsonProperty("caption")]
public IEnumerable<RichTextBaseInput> Caption { get; set; }

public class Data
{
[JsonProperty("url")]
Expand Down
3 changes: 3 additions & 0 deletions Src/Notion.Client/Models/File/FileObject.cs
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,9 @@ public abstract class FileObject : IPageIcon
[JsonProperty("caption")]
public IEnumerable<RichTextBase> Caption { get; set; }

/// <summary>
/// The name of the file block, as shown in the Notion UI. Note that the UI may auto-append .pdf or other extensions.
/// </summary>
[JsonProperty("name")]
public string Name { get; set; }

Expand Down
48 changes: 48 additions & 0 deletions Test/Notion.IntegrationTests/BlocksClientTests.cs
Original file line number Diff line number Diff line change
Expand Up @@ -399,6 +399,54 @@ private static IEnumerable<object[]> BlockData()
.Subject.Should().BeOfType<RichTextText>()
.Subject.Text.Content.Should().Be("Data");
})
},
new object[]
{
new FileBlockRequest {
File = new ExternalFile
{
Name = "Test file",
External = new ExternalFile.Info
{
Url = "https://www.iaspaper.net/wp-content/uploads/2017/09/TNEA-Online-Application.jpg"
},
Caption = new List<RichTextBase>
{
new RichTextTextInput { Text = new Text { Content = "Test file" } }
}
}
},
new FileUpdateBlock
{
File = new ExternalFileInput
{
Name = "Test file name",
External = new ExternalFileInput.Data
{
Url = "https://www.iaspaper.net/wp-content/uploads/2017/09/TNEA-Online-Application.jpg"
},
Caption = new List<RichTextBaseInput>
{
new RichTextTextInput { Text = new Text { Content = "Test file caption" } }
}
}
},
new Action<IBlock, INotionClient>((block, client) =>
{
var fileBlock = block.Should().NotBeNull().And.BeOfType<FileBlock>().Subject;
fileBlock.HasChildren.Should().BeFalse();

var file = fileBlock.File.Should().NotBeNull().And.BeOfType<ExternalFile>().Subject;

// NOTE: The name of the file block, as shown in the Notion UI. Note that the UI may auto-append .pdf or other extensions.
file.Name.Should().Be("Test file name.jpg");

file.External.Should().NotBeNull();
file.External.Url.Should().Be("https://www.iaspaper.net/wp-content/uploads/2017/09/TNEA-Online-Application.jpg");
file.Caption.Should().NotBeNull().And.ContainSingle()
.Subject.Should().BeOfType<RichTextText>().Subject
.Text.Content.Should().Be("Test file caption");
})
}
};
}
Expand Down
Loading