Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[Bug]uploadInfo.isUploadInProgress() always be true even the uploading has finished #25

Open
softboy99 opened this issue Sep 5, 2019 · 6 comments

Comments

@softboy99
Copy link

@controller
@RequestMapping("/upload")
public class FileUploadController {
@value("${tus.server.data.directory}")
protected String tusDataPath;

@Autowired
private TusFileUploadService tusFileUploadService;

@Autowired
private FileUploadService fileUploadService;


//@CrossOrigin(origins = "http://127.0.0.1:8080",exposedHeaders = {"Location","Upload-Offset","Upload-Length"})
@RequestMapping(value = {"", "/**"}, method = {RequestMethod.POST, RequestMethod.PATCH, RequestMethod.HEAD,
        RequestMethod.DELETE, RequestMethod.OPTIONS, RequestMethod.GET})
public void processUpload(final HttpServletRequest servletRequest, final HttpServletResponse servletResponse)  {
   // tusFileUploadService.withUploadURI(servletRequest.getContextPath() + "/upload");
    try {
        tusFileUploadService.process(servletRequest, servletResponse);
        String hLocation = servletResponse.getHeader(HttpHeader.LOCATION);
        if(hLocation!=null){
            while(true){
                UploadInfo ui = tusFileUploadService.getUploadInfo(hLocation);
                if(ui!=null && !ui.isUploadInProgress()) {
                    InputStream uploadedBytes = tusFileUploadService.getUploadedBytes(hLocation);
                    ///////////////////////////// others code here
                    break;
                }
            }
        }

    } catch (IOException | TusException e) {
        e.printStackTrace();
    }
}

}

@ksvraja
Copy link

ksvraja commented Sep 5, 2019

I am not sure, what you are trying to do here..

You can look at the DiskStorageService implementation.

@softboy99
Copy link
Author

what i want is just to move the upload to another disk location when the upload completed. so i need to check ui.isUploadInProgress()

@ksvraja
Copy link

ksvraja commented Sep 6, 2019

you should extend the DiskStorageService class and override the update method.

public void update(UploadInfo info) throws IOException, UploadNotFoundException {
		super.update(info);
		if (!info.isUploadInProgress()) {
			logger.debug("upload completed ");
// Do your stuff here.. 
		}
	}

and make sure while initializing TusFileUploadService set the storageService as your extended class/object -- withUploadStorageService()

@tomdesair
Copy link
Owner

Hi,

The library assumes that the upload is part of some web form. This means that FileUploadController will indeed only see "in progress" uploads as it will process the upload when the user is filling in the rest of the form.

After the user submits the form, a FormSubmissionController will then see all the completed uploads. You can take a look at the Dropwizard example here. I'll try to also extend my Spring Boot example with a form submission flow.

However, this indeed does not cover use cases where the file upload might happen without any web form (e.g. pure file transfers). I'm thinking about adding some kind of TusEvent callback system that would allow users of the library to add custom callbacks/code when certain type of Tus events happen like UPLOAD_CREATED, UPLOAD_COMPLETED, UPLOAD_FAILED, UPLOAD_CHUNK_PROCESSED, UPLOAD_DELETED...

For your use case, you could then add your own TusEventCallback implementation that listens to the UPLOAD_COMPLETED event. It can then do some custom processing on every completed upload like moving the file.

I'll see if I can work something out for this in the code in the coming days/weeks.

@tomdesair
Copy link
Owner

You can also take a look at this example: https://github.com/ralscha/blog2019/blob/51374dd/uploadtus/server/src/main/java/ch/rasc/upload/UploadController.java#L50

This developer seems to be doing something similar as you without the need for a separate form controller.

@ksvraja
Copy link

ksvraja commented Sep 7, 2019

Hi,

The library assumes that the upload is part of some web form. This means that FileUploadController will indeed only see "in progress" uploads as it will process the upload when the user is filling in the rest of the form.

After the user submits the form, a FormSubmissionController will then see all the completed uploads. You can take a look at the Dropwizard example here. I'll try to also extend my Spring Boot example with a form submission flow.

However, this indeed does not cover use cases where the file upload might happen without any web form (e.g. pure file transfers). I'm thinking about adding some kind of TusEvent callback system that would allow users of the library to add custom callbacks/code when certain type of Tus events happen like UPLOAD_CREATED, UPLOAD_COMPLETED, UPLOAD_FAILED, UPLOAD_CHUNK_PROCESSED, UPLOAD_DELETED...

For your use case, you could then add your own TusEventCallback implementation that listens to the UPLOAD_COMPLETED event. It can then do some custom processing on every completed upload like moving the file.

I'll see if I can work something out for this in the code in the coming days/weeks.

Hi Tom,
We would welcome this functionality in the standard library. In our current project, we capture these events by extending few methods on the DiskStorageService class and do some custom processing as we needed.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

3 participants