Search in sources :

Example 1 with TusException

use of me.desair.tus.server.exception.TusException in project servoy-client by Servoy.

the class TusServlet method service.

@Override
protected void service(HttpServletRequest req, HttpServletResponse resp) throws ServletException, IOException {
    tusFileUploadService.process(req, resp);
    String uploadURI = req.getRequestURI();
    UploadInfo uploadInfo = null;
    try {
        uploadInfo = this.tusFileUploadService.getUploadInfo(uploadURI);
    } catch (IOException | TusException e) {
        e.printStackTrace();
    }
    if (uploadInfo != null && !uploadInfo.isUploadInProgress()) {
        try {
            Path uploadedPath = this.tusFileUploadService.getUploadedPath(uploadURI);
            File file = uploadedPath.toFile();
            TusFileItem fileItem = new TusFileItem(file, uploadInfo, uploadURI);
            AbstractMediaResourceServlet.FILE_CLEANING_TRACKER.track(file, file, new TusFileDeleteStategy(fileItem));
            String path = req.getPathInfo();
            if (path.startsWith("/"))
                path = path.substring(1);
            String[] paths = path.split("/");
            int clientnr = paths[1].length() == 0 ? -1 : Integer.parseInt(paths[1]);
            final INGClientWebsocketSession wsSession = getSession(req, clientnr);
            if (wsSession != null) {
                // clear out the tus id that is the last path entry (so it is not confused with the row id)
                paths[paths.length - 1] = null;
                JSMap<String, String> map = new JSMap<>();
                map.putAll(uploadInfo.getMetadata());
                callClient(req, paths, wsSession, map, fileItem);
            }
        } catch (IOException | TusException e) {
            Debug.error(e);
        }
    }
}
Also used : UploadInfo(me.desair.tus.server.upload.UploadInfo) Path(java.nio.file.Path) JSMap(com.servoy.j2db.scripting.JSMap) IOException(java.io.IOException) TusException(me.desair.tus.server.exception.TusException) IFile(com.servoy.j2db.plugins.IFile) File(java.io.File)

Aggregations

IFile (com.servoy.j2db.plugins.IFile)1 JSMap (com.servoy.j2db.scripting.JSMap)1 File (java.io.File)1 IOException (java.io.IOException)1 Path (java.nio.file.Path)1 TusException (me.desair.tus.server.exception.TusException)1 UploadInfo (me.desair.tus.server.upload.UploadInfo)1