tomdesair / tus-java-server

Library to receive tus v1.0.0 file uploads in a Java server environment
MIT License
133 stars 62 forks source link

Method to add URL sent to Tus client? #33

Closed techied closed 10 months ago

techied commented 4 years ago

I'm implementing this library to replace XHR Upload with the Uppy client.

My implementation is very similar to the demos provided:

    @RequestMapping(value = {"/tusUpload", "/tusUpload/**"}, method = {RequestMethod.POST,
            RequestMethod.PATCH, RequestMethod.HEAD, RequestMethod.DELETE, RequestMethod.GET})
    public void upload(HttpServletRequest servletRequest,
                       HttpServletResponse servletResponse) throws IOException {
        tusFileUploadService.process(servletRequest, servletResponse);
        String uploadURI = servletRequest.getRequestURI();

        UploadInfo uploadInfo = null;
        try {
            uploadInfo = tusFileUploadService.getUploadInfo(uploadURI);
        } catch (IOException | TusException e) {
            e.printStackTrace();
        }

        if (uploadInfo != null && !uploadInfo.isUploadInProgress()) {
            try (InputStream stream = tusFileUploadService.getUploadedBytes(uploadURI)) {
                String uploadURL = upload(new MockMultipartFile(uploadInfo.getFileName(), uploadInfo.getFileName(), uploadInfo.getFileMimeType(), IOUtils.toByteArray(stream))); // I know this is poor practice, just wanted to get something working first.
                System.out.println(response);
// what to do here to tell the Uppy client what URL it's uploaded at?
            } catch (IOException | TusException e) {
                e.printStackTrace();
            }
            try {
                tusFileUploadService.deleteUpload(uploadURI);
            } catch (IOException | TusException e) {
                e.printStackTrace();
            }
        }

My question is: What's the method (Is there one?) to tell the Uppy client the stored URL? Currently the client receives a URL, however it's not one that's hosted permanentlly (my uploadURL string is what I want the client to display).

URL the Uppy client displays for the "Copy Link" button and when clicking on the file's icon: /tusUpload/f23a6d79-5bd8-4d50-8904-215752aaf483