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

Deleting .info files and moving uploaded file to another directory after upload complete #45

Closed
kathirvelkg opened this issue Apr 22, 2016 · 6 comments

Comments

@kathirvelkg
Copy link

kathirvelkg commented Apr 22, 2016

After successful upload, I need to move the uploaded file(.bin) to another directory and delete the .info file which is not need after that. Is there any call back function I can use to perform this operation.
And please let me know whether the following is feasible:
I have 'n' number of clients uploading files; I want to store the files in separate directory with respect to the client uploading it. This may be a feature of file server; but I foresee tus as a upload file server rather than just a uploading protocol.

@kathirvelkg kathirvelkg changed the title Deleting .info files and moving to another directory after upload complete Deleting .info files and moving uploaded file to another directory after upload complete Apr 22, 2016
@Acconut
Copy link
Member

Acconut commented Apr 24, 2016

Is there any call back function I can use to perform this operation.

If you use tusd programmatically using it's Go API, you can listen on the CompleteUploads channel in your handler struct (https://godoc.org/github.com/tus/tusd#UnroutedHandler). In the case that you are simply running the tusd binary, we currently have a hook system which allows you to run scripts whenever an upload is finished. However, this feature is not well documented yet, but you can try it:

tusd -hooks-dir ./hooks/

This will cause the ./hooks/post-finish file to be executed if an upload finishes. The process will have special environment variables (and can read from stdin) for more information about the upload (see https://github.com/tus/tusd/blob/master/cmd/tusd/main.go#L182).

I have 'n' number of clients uploading files; I want to store the files in separate directory with respect to the client uploading it.

I guess, the best way to implement this is to move the files after they have been uploaded and not in the beginning. You can use the hooks system for this as described above.

@kathirvelkg
Copy link
Author

kathirvelkg commented Apr 25, 2016

Thanks for the quick and detailed reply. hooks system will solve my problem and have gone through the hooks function.
I have developed the upload client using tus java client library; now the requirement is I should move the customer uploaded files under their directory; not to store all files in same directory. Is there any way I can share the customer guid to the server/ store it in the info.json; then I can use post finish hook to move the file to respective directory.

@Acconut
Copy link
Member

Acconut commented Apr 25, 2016

You can use the TusUpload#setMetadata method to add optional information to an upload:

TusUpload upload = new TusUpload(/* ... */);
Map<String, String> meta = upload.getMetadata();
meta.put("client_id", "55");
upload.setMetadata(meta);

This will then show up in the .info file in the MetaData object.

@kathirvelkg
Copy link
Author

Thanks for the update. Hope this solves my problem. Will check and update

@kathirvelkg
Copy link
Author

kathirvelkg commented May 2, 2016

The following code
Map<String, String> meta = upload.getMetadata();
always returns null and adding new <k,v> pair throws null pointer exception.
I followed the same code which you have mentioned, since it returned null; I used
Map<String, String> meta = new HashMap<String, String>(); and it worked.

@Acconut
Copy link
Member

Acconut commented May 3, 2016

That's correct. It's not guaranteed that the object returned is not null. I will make sure to update the documentation to fix this.

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

No branches or pull requests

2 participants