Associating Files with Data Items

If you have already uploaded a file and have its ID, you can assign it to a content type item as a value. The Telerik Platform portal automatically expands File IDs of pictures and displays a thumbnail in the details pane.

In this article:

Creating Associations

Creating an association to a file is as simple as setting the desired file field value of the content type to a file ID.

var el = new Everlive('your-app-id');
var item = {
    Id: 'item-id',
    'Picture': 'file-id'
};
var data = el.data('type-name');
data.updateSingle(item,
    function(data){
        alert(JSON.stringify(data));
    },
    function(error){
        alert(JSON.stringify(error));
    });

Removing Associations

Deleting a file from the database does not unlink it from the items that are associated with it. Remember to remove the association with an additional request.

Single Association

Use updateSingle() to set an empty string to your item's file field.

var el = new Everlive('your-app-id');
var item = {
    Id: 'item-id',
    'Picture': ''
};
var data = el.data('type-name');
data.updateSingle(item,
    function(data){
        alert(JSON.stringify(data));
    },
    function(error){
        alert(JSON.stringify(error));
    });

All Associations

To delete all references to a given file, use a filter that finds all referenced to the file in question and then use update() to set the matching items' file fields to an empty string.

var el = new Everlive('your-app-id');
var query = new Everlive.Query();
query.where().eq('Picture', 'file-id');
el.Files.update({ 'Picture': '' }, // the modified field
query, // filter
    function (data) {
        alert('Items successfully deleted.');
    },
    function(error){
        alert(JSON.stringify(error));
    });

Reading Associations

Associating a file to a data item creates a relation to the Files content type. Most of the time, you will need to expand the information behind it to read the file's Uri or another metadata attribute.

It is important to note that you need to use the System.Files notation when referring the Files content type in relation expansion expressions. See Expand Expression Examples for example code.

Start a free trial Request a demo
Contact us: +1-888-365-2779
sales@telerik.com
Copyright © 2016-2017, Progress Software Corporation and/or its subsidiaries or affiliates. All rights reserved.