Creating Binary Schema
Add Path: Application name --> SiteManager --> Schema --> Binary, Click "New" button to open adding screen.
Name is required, the rest is optional
Using Binary Schema Content
There are two major ways of using Binary content.
1. Use it as a referred content/attachment by Text content.
2. Use it directly. For example, download documents.
Same as Text content, first we need to create a Binary content folder in order to store uploaded binary data.
Create Folder
Add Path: Application name --> Content
Right click on "Content" and then select "Add Folder" menu. You do it exactly the same way as Text schema except that you select a binary schema instead.
Folder Name: Any name.
Schema: The Binary Schema
Other columns will be same as Text Schema.
After that, you can upload binary files:
Referred by Text Schema
On the Text Schema definition page, you can specify the Binary Schema you want to use. On the content input form, content of that Binary schema will be showed in dropdown list to be selected from.
Go to the "content" input form, you will be able to see a dropdown list with binary content to select from.
Click on "select" will open the binary content selection window as below; you can easily drag and drop to select the binary content.
The selected binary files will be attached to the text content. You can use below API method to query binary files of text content at front end website, includes Binary Schema content and "File included".
ContentService.GetAttachments(contentId);
This method returns an IEnumerable<FileInContent>, FileInContent entity as below:
public class FileInContent
{
public FileInContent();
public string BinaryContentTitle { get; set; }
public Guid BinaryContentUUID { get; set; }
public string FileUrl { get; set; }
}
For a complete example, you may have code like below.
foreach (var item in this.ContentService.GetAttachments(Convert.ToInt32(this.GetContent("article")["ContentId"])))
{
Response.Write(@""); Response.Write(item.BinaryContentTitle.ToString()); Response.Write("
"); Response.Write(@"
Use directly in your code
Binary content can be queried by Kooboo Data Rule as well. Exactly same as Text content. The List Data Type will return IEnumerable<IDictionary<string, object>>. Below are the keys included in this dictionary object.
|
Field |
Type |
|
ContentId |
Int |
|
Application |
String |
|
UUID |
Guid |
|
PostDate |
DateTime |
|
FileSize |
Int |
|
FileUrl |
String |
|
Title |
String |
|
UserName |
String |
Define a DataRule called "myphoto" which reads content from a binary schema folder and use below code to try it yourself.
Url.ResolveUrl
From Kooboo 2.0, we have added a new method to resolve all binary file url. Url.ResolveUrl. Please add this method to all file URLs like above examples. This is mainly because Kooboo is now possible to run under IIS website Virtual Directory. Url.ResolveUrl will determine current file base url and append that to it.
