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.

Request:
    PUT https://api.everlive.com/v1/your-app-id/type-name/item-id
Headers:
    Authorization  Bearer your-access-token
    Content-Type: application/json
Body:
    { "$set" : { "Picture" : "file-id" } }

Response:
    Status: 200 OK
    Content-Type: application/json
var exp = {
    '$set' : { "Picture" : "file-id" }
};

$.ajax({
    type: "PUT",
    url: 'https://api.everlive.com/v1/your-app-id/type-name/item-id',
    headers: { "Authorization" : "Bearer your-access-token" },
    contentType: "application/json",
    data: JSON.stringify(exp),
    success: function(data){
        alert(JSON.stringify(data));
    },
    error: 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

Request:
    PUT https://api.everlive.com/v1/your-app-id/type-name/item-id
Header:
    Authorization  Bearer your-access-token
Payload - raw:
    { "$set" : { "Picture" : "" } }
Response:
    Status: 200 OK
    Content-Type: application/json
var exp = { $set: {"Picture": ""} };

$.ajax({
    type: "PUT",
    url: 'https://api.everlive.com/v1/your-app-id/type-name/item-id',
    headers: {"Authorization" : "Bearer your-access-token"},
    contentType: "application/json",
    data: JSON.stringify(exp),
    success: function (data) {
        alert(JSON.stringify(data));
    },
    error: function (error) {
        alert(JSON.stringify(error));
    }
})

All Associations

In order to delete all references to a given file you will need to make a request in the content type.

Request:
    PUT https://api.everlive.com/v1/your-app-id/type-name
Header:
    Authorization  Bearer your-access-token
    X-Everlive-Filter { "Picture" : "file-id" }
Payload - raw:
    { "$set" : {"Picture": ""} }
Response:
    Status: 200 OK
    Content-Type: application/json
var exp = {
    $set: {"Picture": ""}
};
var filter = {"Picture":"file-id"};

$.ajax({
    type: "PUT",
    url: 'https://api.everlive.com/v1/your-app-id/type-name',
    headers: {
        "Authorization" : "Bearer your-access-token",
        "X-Everlive-Filter" : JSON.stringify(filter)
    },
    contentType: "application/json",
    data: JSON.stringify(exp),
    success: function (data) {
        alert(JSON.stringify(data));
    },
    error: 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.