Package io.milton.annotations
Annotation Interface PutChild
Marks a method as one which creates a child resource containing the given content,
or replaces an existing child's content with new data
Return type - Must return the created POJO object, or the updated child
Parameters:
- first arg must be the object to update OR..
- the parent object, followed by the name of the child resource
- items following that may include (in preferential order)
- inputStream or byte[]
- contentType
- content length as Long
Example: Creating a new child resource
@PutChild
public MyDatabase.FileContentItem createFile(MyDatabase.FolderContentItem parent, String name, byte[] bytes) {
FileContentItem file = parent.addFile(name);
file.setBytes(bytes);
return file;
}
Example: updating an existing resource
@PutChild
public Image uploadImage(Image image, byte[] bytes) throws IOException {
File fRoot = getContentRoot();
File content = new File(fRoot, image.getFileName());
FileUtils.writeByteArrayToFile(content, bytes);
return image;
}
Example: Creating a new child resource from an inputstream. This uses the contentLength and contentType headers, but please note these are not always sent by client apps.
@PutChild
public MyDatabase.FileContentItem createFile(MyDatabase.FolderContentItem parent, String name, InputStream in, Long contentLength, String contentType) {
...
}