Comments (7)
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.
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.
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.
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.
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.
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.
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)
- Configuration Custom File Id Provider HOT 3
- Expired Files Cleanup Service on multiple folder HOT 1
- 409 http status code when trying to resume upload after broken connection HOT 4
- Rewrite the client discconect guard to support timeouts
- Can't delete meta files before response back from my .Net core application HOT 1
- When can we expect Tus 2.0 implementation for .NET? HOT 5
- Upload similiar file twice issue HOT 5
- Exceptions thrown during OnFileCompleteAsync get swallowed when using create during creation HOT 1
- Custom data store enquery HOT 2
- Events OnBeforeDeleteAsync and OnDeleteCompleteAsync not firing HOT 2
- Handle file name with symbol like # HOT 1
- Update to .NET 8 HOT 2
- Cannot upload input stream directly to Azure Storage without loading stream in memory HOT 2
- UseTus or MapTus? HOT 2
- How to implement file encryption? HOT 2
- Possibility to override or re-set the Store Path value on the event HOT 3
- bug: write custom data to the response fails with error HOT 2
- Possibility to Abort Upload Process at the Initial Event HOT 4
- Adding endpoints to an OpenAPI specification HOT 2
- If other routing middleware has already been used, such as Carter, how to combine tusdotnet with it to handle the same request
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
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.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from tusdotnet.