notion-dotnet / notion-sdk-net

A Notion SDK for .Net
MIT License
181 stars 44 forks source link

Adds support to read and write names for the file blocks. #412

Open KoditkarVedant opened 3 months ago

KoditkarVedant commented 3 months ago

Description

Adds support to read and write names for the file blocks.

Now, when you retrieve a file block (uploaded or external file), the name of the file is included in the response. For example:

"file": {
  "type": "external",
  "external": {
    "url": "https://example.com/my-file.pdf"
  },
  "caption": [],
  "name": "my-file.pdf"
}

Also, it supports setting a custom file name when adding a file block (external file only, since Notion API doesn't support uploading files).

var request = new BlockAppendChildrenRequest()
{
    BlockId = "xxx",
    After = "yyy",
    Children = new List<IBlockObjectRequest>()
    {
        new FileBlockRequest()
        {
            File = new ExternalFile()
            {
                External = new ExternalFile.Info()
                {
                    Url = "https://example.com/my-external-file.pdf"
                },
                Name = "my-custom-file-name.pdf"
            }
        }
    }
};

await _notionClient.Blocks.AppendChildrenAsync(request);

Documentation reference: