Coder Social home page Coder Social logo

Comments (6)

Acconut avatar Acconut commented on July 18, 2024

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.

from tusd.

kathirvelkg avatar kathirvelkg commented on July 18, 2024

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.

from tusd.

Acconut avatar Acconut commented on July 18, 2024

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.

from tusd.

kathirvelkg avatar kathirvelkg commented on July 18, 2024

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

from tusd.

kathirvelkg avatar kathirvelkg commented on July 18, 2024

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.

from tusd.

Acconut avatar Acconut commented on July 18, 2024

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.

from tusd.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.