API Reference: FileUploadAttribute Class
The FileUploadAttribute
can be applied to asset content models. The attribute specifies that assets of this model can be created through uploading files directly in an asset library. This simplifies (bulk) creation of media assets in the back office. If this attribute is not set, assets of this model can only be created individually by selecting the "New" command in the back office user interface.
When files are uploaded in this way, the system only populates the file property of the asset content. If the model contains other properties that are required or have validation, the asset content may result in an invalid state. These properties will still need to be set by the content editor to valid values after the file upload has been completed. This can be mitigated by implementing and setting a custom IFileUploadHandler. The IFileUploadHandler.HandleFileUploadAsync() method gets called immediately after the file has been uploaded, but before the content has been saved. Within this method, you can populate any other content properties to default or computed values.
When using the FileUploadAttribute, it is recommended to either not have properties on the model that result in an invalid state, or set a custom IFileUploadHandler to populate content to a valid state. This may prevent errors caused by invalid content and reduce the need for content editors to go back and revise newly created assets.
Usage
Decorate the asset content model class with the FileUploadAttribute. The attribute is not inherited from base types.
Example
[Asset]
[FileUpload]
public class Image: IContentType
{
[AcceptMediaType("image/jpeg", "image/gif", "image/png", "image/bmp", "image/tiff", "image/svg+xml")]
public Media File { get; set; }
[CultureDependent]
public string AlternateText { get; set; } // Not required so will not result in an invalid content state after upload.
}