Commit c8257178 authored by Matija Obreza's avatar Matija Obreza
Browse files

Downloading files from repository

parent 6cc63c67
......@@ -20,6 +20,7 @@ import java.io.FileNotFoundException;
import java.io.IOException;
import java.util.UUID;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import org.apache.commons.logging.Log;
......@@ -32,6 +33,7 @@ import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.servlet.HandlerMapping;
@Controller
public class FileRepositoryController extends BaseController {
......@@ -41,10 +43,11 @@ public class FileRepositoryController extends BaseController {
@Autowired
private RepositoryService repositoryService;
@RequestMapping(value = "/repository/{uuid}.{ext}", method = RequestMethod.GET)
@RequestMapping(value = "/repository/d/{uuid:[\\d+\\-]+}.{ext}", method = RequestMethod.GET)
public void downloadFile(@PathVariable String uuid, @PathVariable String ext, HttpServletResponse response) throws IOException {
try {
RepositoryFile repositoryFile = repositoryService.getFile(UUID.fromString(uuid));
byte[] data = repositoryService.getFileBytes(repositoryFile.getPath(), repositoryFile.getFilename());
if (repositoryFile != null && data != null) {
......@@ -60,9 +63,18 @@ public class FileRepositoryController extends BaseController {
}
}
@RequestMapping(value = "/repository/{path:.+}/{uuid}.{ext}", method = RequestMethod.GET)
public void downloadFileWithPath(@PathVariable String path, @PathVariable String uuid, @PathVariable String ext, HttpServletResponse response)
throws IOException {
@RequestMapping(value = "/repository/d/**", method = RequestMethod.GET)
public void downloadFile(HttpServletRequest request, HttpServletResponse response) throws IOException {
String fullpath = (String) request.getAttribute(HandlerMapping.PATH_WITHIN_HANDLER_MAPPING_ATTRIBUTE);
System.err.println("Fullname: " + fullpath);
String ext = fullpath.substring(fullpath.lastIndexOf("."));
String uuid = fullpath.substring(fullpath.lastIndexOf("/") + 1, fullpath.lastIndexOf("."));
System.err.println(ext);
System.err.println(uuid);
if (LOG.isDebugEnabled()) {
LOG.debug("ext=" + ext + " uuid=" + uuid);
}
downloadFile(uuid, ext, response);
}
......
......@@ -43,7 +43,7 @@
<c:forEach var="file" items="${fileList}" varStatus="i">
<tr>
<td class="col-md-4">
<a href="<c:url value="/repository${currentPath}${file.uuid}${file.extension}" />"> <c:out value="${file.title}" /> <small>${file.originalFilename}</small></a>
<a href="<c:url value="/repository/d/${file.uuid}${file.extension}" />"> <c:out value="${file.title}" /> <small>${file.originalFilename}</small></a>
</td>
<td class="col-md-4">
<c:out value="${file.path}" />
......
......@@ -7,5 +7,6 @@
code="menu.admin.ds2"
/></a> <a class="" href="<c:url value="/admin/kpi/" />"><spring:message code="menu.admin.kpi" /></a>
<a href="<c:url value="/admin/elastic/" />" class="">Elasticsearch</a>
<a href="<c:url value="/admin/repository/files" />" class="">Repository</a>
</div>
</div>
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment