A binary object (this can be an image, attachment, etc.) is a separate entity. It has
the Name
, Mime
properties and, actually, data (Stream
).
This entity can be stored in a separate table for each item, as well as in a common table of
attachments with an additional table of relations. An access token generation mechanism is
used to prevent unauthorized access to attachments. A token is simply a hash of a string
containing the ID of the current session, the user ID, and the additional access key (guid)
associated with that attachment. The simplest way is to add this key as a field with a
uniqueidentifier
type and a default newid()
value.
Working with binary objects actually consists of three almost independent parts.
!Token
. type into the recordset. When processing this field, the system will
take a value (this will be guid) and generate an access token instead. Note that the values
of this token will be different in different browser sessions.
Two stored procedures are used to work with binary data. One for reading data (.Load
suffix),
another for their recording (.Update
suffix). Note that the procedures for working with binary
data are specific and do not comply with the rules for building models.
.Load
ProcedureThe procedure receives the following parameters (the names are fixed, the order does not matter):
@TenantId int
- tenant ID (only in a multitenant environment).@UserId bigint
- current user ID.@Id bigint
- data (image, attachment) ID.The procedure must return a single record set with the following fields (field names matter, their order is arbitrary).
Id bigint
- data (image, attachment) ID.Mime nvarchar(255)
- mime data type.Name nvarchar(255)
- the recordset name.Stream varbinary(max)
- the data stream itself. Can be equal to null.BlobName nvarcvhar(max)
- the name of the set in external storage (e. g. Azure Storage). Can be equal to null.
Token uniqueidentifier
- the field for generating the access token. This item must correspond to what the load
procedure of the model, from which this data will be received, will return.
The download procedure must return one of the fields BlobName
or Stream
.
If the BlobName
field is specified, the data will be retrieved from external storage
(Azure Storage) and the value of the Stream
field will be ignored.
.Update
ProcedureThe procedure receives the following parameters (the names are fixed, the order does not matter):
@TenantId int
- tenant ID (only in a multitenant environment).@UserId bigint
- current user ID.@Name nvarchar(255)
- the recordset name.@Mime nvarchar(255)
- mime data type.@Stream varbinary(max)
- the data stream itself or null, if the data is stored in external storage.@BlobName nvarcvhar(max)
- the set name in external storage or null.The procedure must return a single set with the following fields (field names matter, order not important).
Id bigint
- data (image, attachment) ID.Token uniqueidentifier
- field for generating the access token.
The data returned by this procedure will be returned to the client, who will need to add it to their data model.
model.json
file.