Skip to content

Commit

Permalink
pcorlessGH-46 Creates directory if not exists
Browse files Browse the repository at this point in the history
  • Loading branch information
gtache committed Jul 7, 2020
1 parent f1a7663 commit e579688
Showing 1 changed file with 14 additions and 2 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -80,8 +80,20 @@ public void save(final InputStream inputStream) throws IOException {
if (mimeType == null || mimeType.equals("application/octet-stream")) {
mimeType = new Tika().detect(name + "." + ext);
}
final String newUrl = folderUrl + "/" + name + "." + ext;
sardine.put(newUrl, inputStream, mimeType);
if (!sardine.exists(folderUrl)) {
final List<String> split = Arrays.asList(folderUrl.split("/"));
for (int i = split.size(); i > 1; --i) {
final String parentUrl = String.join("/", split.subList(0, i));
if (sardine.exists(parentUrl)) {
for (int j = i; j < split.size(); ++j) {
final String toCreate = String.join("/", split.subList(0, j));
sardine.createDirectory(toCreate);
}
break;
}
}
}
sardine.put(url, inputStream, mimeType);
revision += 1;
}
}
Expand Down

0 comments on commit e579688

Please sign in to comment.