use of org.structr.web.common.FileHelper.Base64URIData in project structr by structr.
the class FileDataConverter method convert.
@Override
public Object convert(final Object source) throws FrameworkException {
if (source == null) {
return false;
}
final File currentFile = (File) getCurrentObject();
if (source instanceof byte[]) {
try {
byte[] data = (byte[]) source;
MagicMatch match = Magic.getMagicMatch(data);
String mimeType = match.getMimeType();
try {
FileHelper.setFileData(currentFile, data, mimeType);
} catch (IOException ioex) {
logger.warn("Unable to store file", ioex);
}
} catch (MagicException | MagicParseException | MagicMatchNotFoundException mex) {
logger.warn("Unable to parse file data", mex);
}
} else if (source instanceof String) {
String sourceString = (String) source;
if (StringUtils.isNotBlank(sourceString)) {
final Base64URIData uriData = new Base64URIData(sourceString);
try {
FileHelper.setFileData(currentFile, uriData.getBinaryData(), uriData.getContentType());
} catch (IOException ioex) {
logger.warn("Unable to store file", ioex);
}
}
}
return null;
}
Aggregations