GET:files/{fileid}

Overview

public. Retrieve file attachment content

Uri Parameters
Name Type Description
fileid int identifies a file by ID
Query Parameters
Name Type Description
format {jpg, png, bmp, gif}? Convert output to given type. Default is to use original type.
height int? Height of the image
ratio {fixed, var}? Fixed preserves aspect ratio by applying height and width as bounding maximums rather than absolute values. Variable will use the width and height given. Default: fixed
redirects int? If zero, do not follow page redirects (only applies when {pageid} is present).
revision string? File revision to retrieve. 'head' by default will retrieve latest revision. positive integer will retrieve specific revision
size {original, thumb, webview, bestfit, custom}? Return a resized image from one of the preset cached sizes. Use 'thumb' or 'webview' to return a smaller scaled image. Use 'bestfit' along with height/width to return one of the known sizes being at least the size given. Default: original
width int? Width of the image
Return Codes
Name Value Description
BadRequest 400 Invalid input parameter or request body
Forbidden 403 Read access to the page is required
NotFound 404 Requested file could not be found
NotImplemented 501 Requested operation is not currently supported
Ok 200 The request completed successfully

Message Format

None

Implementation Notes

Use of the format, ratio, width/height, and size parameters requires the file to be an image. 

The Content-Disposition, Content-Length, and Content-Type headers provide information about the retrieved file.

Use GET:files to retrieve a list of files across the site or GET:pages/{pageid}/files to retrieve the files on a specified page.

Code Samples

The following code example retrieves the file with ID 456 using a best fit of 100x100 and saves it in the caller's temporary directory:

Plug p = Plug.New("http://deki-hayes/@api/deki");
p.At("users", "authenticate").WithCredentials("admin", "password").Get();
DreamMessage msg = p.At("files", "456")
                    .With("size", "bestfit")
                    .With("width", 100)
                    .With("height", 100).Get();
using (FileStream fs = System.IO.File.OpenWrite(Path.GetTempPath() + msg.ContentDisposition.FileName)) 
{
    byte[] fileData = msg.AsBytes();
    fs.Write(fileData, 0, fileData.Length);
}

  

Tag page
You must login to post a comment.
Powered by MindTouch Deki Enterprise Edition v.8.08 RC2