Giter Site home page Giter Site logo

Comments (7)

smatsson avatar smatsson commented on May 9, 2024 1

Hi @KhaledSMQ

You can already achieve this as you have access to the store. Cast the store to the ITusCreationStore interface and use GetUploadMetadataAsync method to get the raw metadata. Then parse it using the tusdotnet.Models.metadata model. I want to keep the callback context's as lean as possible and not load data that might not be needed.

OnCreateCompleteAsync = async ctx =>
                    {
                        var metadataString = await ((tusdotnet.Interfaces.ITusCreationStore) ctx.Store).GetUploadMetadataAsync(ctx.FileId, ctx.CancellationToken);
                        var metadataDict = tusdotnet.Models.Metadata.Parse(metadataString);

                        var myValue = metadataDict["myKey"].GetString(Encoding.UTF8);
                        //var myValue = metadataDict["myKey"].GetBytes();
                    },

It is probably a good idea to add this as an extension method to all event context's though as the above code is a bit chatty and not very straight forward to other people than myself :D

Please let me know if this solved your issue and feel free to report any other issues you might have.

EDIT: You could also cast directly to TusDiskStore (if that is the one you are using?) to get access to the GetUploadMetadataAsync method (and others).

from tusdotnet.

smatsson avatar smatsson commented on May 9, 2024 1

Just realized that if you follow the example in the readme you can also just grab the metadata directly from the file as such:

OnCreateCompleteAsync = async ctx =>
                    {
                        var file = await ((ITusReadableStore)ctx.Store).GetFileAsync(ctx.FileId, ctx.CancellationToken);
                        var metadata = await file.GetMetadataAsync(ctx.CancellationToken);
                        var myValue = metadata["myKey"].GetString(Encoding.UTF8);
                    },

Either way is fine. :)

from tusdotnet.

KhaledSMQ avatar KhaledSMQ commented on May 9, 2024 1

actually this is what i did

OnCreateCompleteAsync = ctx =>
                    {
                        if (!ctx.Metadata.ContainsKey("app")) return Task.CompletedTask;
                        try
                        {
                            ctx.Metadata.TryGetValue("app", out var contentTo);
                            var ContentBytes = contentTo.GetBytes();
                            var app = Encoding.UTF8.GetString(ContentBytes);
                      }.......

from tusdotnet.

KhaledSMQ avatar KhaledSMQ commented on May 9, 2024

Thank you @smatsson , That useful and i already manage to solve it using OnCreateCompleteAsync event.

Thank you for Tus project, it's just amazing and clean code.

from tusdotnet.

smatsson avatar smatsson commented on May 9, 2024

You are very welcome @KhaledSMQ ! Thanks for the kind words :) I'll look into making it easier to read metadata etc in events in an upcoming release.

from tusdotnet.

KhaledSMQ avatar KhaledSMQ commented on May 9, 2024

but i am not sure so i will give a try for the one give.
I just wonder if I can create an extensions for the server i have a use case for the images to optimize. right now i am just do that right after the upload complete.
what do you think and what is your advice.

from tusdotnet.

smatsson avatar smatsson commented on May 9, 2024

As a first step I would probably just do the image optimization in the OnFileComplete event. Something similar to what is shown in the readme: https://github.com/tusdotnet/tusdotnet#configure (implement the DoSomeProcessing method).

from tusdotnet.

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.