Get contents of an asset
Returns the content of an asset. The Content-Type header on the HTTP response will be set to the value that was specified when creating the asset.
The example below, retrieves a JSON asset (92a572b1-35ea-40e1-a871-0934efeb210a) from an application(543cce56-c950-4c7f-9dcc-53bcb3e90a4a). Note the HTTP Content-Type
is set to 'application/javascript' matching the content_type
field value that was set when creating this asset.
curl -v -i --user "543cce56-c950-4c7f-9dcc-53bcb3e90a4a:Mry2oK3GSjy78O2WyORgJQ" https://api.lumenpath.com/api/asset/543cce56-c950-4c7f-9dcc-53bcb3e90a4a/asset/92a572b1-35ea-40e1-a871-0934efeb210a/content/
Response
========
> GET /api/asset/543cce56-c950-4c7f-9dcc-53bcb3e90a4a/asset/92a572b1-35ea-40e1-a871-0934efeb210a/content/ HTTP/1.1
> Authorization: Basic NTQzY2NlNTYtYzk1MC00YzdmLTlkY2MtNTNiY2IzZTkwYTRhOm0zS0l5SmhhU0pLbS1uR0RCSFdYekE=
...
...
< HTTP/1.1 200 OK
< Content-Length: 21
< Content-Type: application/javascript
....
{
"foo" : "bar"
}
Retrieving a Redirect-URL asset
If an asset is of type Redirect-URL
, the API response will issue a redirect to the URL stored in the asset content field. In the example below, we first create a an asset with the content_type
set to 'text/x-redirect-url' and content set to the Base64 encoded value of http://www.lumenpath.com/
#Create a Redirect-URL asset, pointing to http://www.lumenpath.com
curl --user "543cce56-c950-4c7f-9dcc-53bcb3e90a4a:m3KIyJhaSJKm-nGDBHWXzA" https://api.lumenpath.com/api/asset/543cce56-c950-4c7f-9dcc-53bcb3e90a4a/asset/ -d '{"content_type" : "text/x-redirect-url", "content" : "aHR0cDovL3d3dy5sdW1lbnBhdGguY29tLw==" }' -X PUT -H "Content-Type: application/json"
Response
========
{"id":"92a572b1-35ea-40e1-a871-0934efeb210a","created_on":"2014-11-07T20:04:45.872Z","modified_on":"2014-11-07T20:04:45.872Z","content_type":"application/javascript","size":21,"metadata":{"default":{"name":"Test Json"}},"content_url":"https://api.lumenpath.com/api/asset/1:543cce56-c950-4c7f-9dcc-53bcb3e90a4a/asset/92a572b1-35ea-40e1-a871-0934efeb210a/content/"}
#Retrieve the asset content with curl. Notice that the reponse will contain a 303 redirect.
curl -v --user "543cce56-c950-4c7f-9dcc-53bcb3e90a4a:m3KIyJhaSJKm-nGDBHWXzA" http://localhost:9000/api/asset/543cce56-c950-4c7f-9dcc-53bcb3e90a4a/asset/7d34b7cc-597f-47c4-8084-206deb7d6491/content/
Response
========
> GET /api/asset/543cce56-c950-4c7f-9dcc-53bcb3e90a4a/asset/7d34b7cc-597f-47c4-8084-206deb7d6491/content/ HTTP/1.1
> Authorization: Basic NTQzY2NlNTYtYzk1MC00YzdmLTlkY2MtNTNiY2IzZTkwYTRhOm0zS0l5SmhhU0pLbS1uR0RCSFdYekE=
....
....
< HTTP/1.1 303 See Other
< Location: http://www.lumenpath.com/
...
< Content-Length: 0
...
#Most HTTP clients and browsers will follow the redirect automatically. User the -L option to force curl to follow the redirect
curl -v -L --user "543cce56-c950-4c7f-9dcc-53bcb3e90a4a:m3KIyJhaSJKm-nGDBHWXzA" http://localhost:9000/api/asset/543cce56-c950-4c7f-9dcc-53bcb3e90a4a/asset/7d34b7cc-597f-47c4-8084-206deb7d6491/content/
Response
========
> GET /api/asset/543cce56-c950-4c7f-9dcc-53bcb3e90a4a/asset/7d34b7cc-597f-47c4-8084-206deb7d6491/content/ HTTP/1.1
> Authorization: Basic NTQzY2NlNTYtYzk1MC00YzdmLTlkY2MtNTNiY2IzZTkwYTRhOm0zS0l5SmhhU0pLbS1uR0RCSFdYekE=
....
....
< HTTP/1.1 303 See Other
< Location: http://www.lumenpath.com/
...
< Content-Length: 0
<
* Issue another request to this URL: 'http://www.lumenpath.com/'
...
...
* Connected to www.lumenpath.com (54.81.60.34) port 80 (#1)
> GET / HTTP/1.1
> User-Agent: curl/7.37.0
> Host: www.lumenpath.com
> Accept: */*
>
< HTTP/1.1 200 OK
...
...
< Date: Fri, 07 Nov 2014 20:38:40 GMT
< Content-Type: text/html
< Content-Length: 38775
< Last-Modified: Tue, 28 Oct 2014 05:09:08 GMT
< Connection: keep-alive
< ETag: "544f24f4-9777"
< Accept-Ranges: bytes
<
<!DOCTYPE html>
....