Comments (12)
Thanks for sharing. We can't allow to override the entire upload, only metadata should be allowed, and the metadata should be validated as well. It's also important to make it backwards compatible to prevent a breaking change.
I'll take next week probably. Created an issue: #594
from tus-node-server.
Hi, this is an XY problem. What is the problem you are trying to solve? Are you only communicating between hooks or does the client also need to know this value?
Maybe you can just do it in server memory with a Map
. Or if it needs to survive server restarts, put it in something like Redis?
from tus-node-server.
I'm sorry, here is the problem:
I need to pass a variable from the onUploadCreate
function to the onUploadFinish
function. It does not need to be sent back to the client.
Is there a way to do this?
If not, then I'll look into your other suggestions, thank you!
from tus-node-server.
I don't know the requirements and why you are trying to pass that variable. There are many ways to write/read to different things depending on what you are doing, but those all fall into your hands and setup, there is no built-in way of doing this.
from tus-node-server.
I'm sorry for being unclear.
I'm using the onUploadCreate
function to validate the upload request, a process that generates a unique ID that I need to get in the onUploadFinish
function.
Redis would be a way to do this, but I was hoping that I could simply update the metadata of the upload, but it sounds like that is not an option, correct?
from tus-node-server.
If you tell me why you need the ID to be accessible by the onUploadFinish
hook, we can see if there are alternative approaches.
You can't change the metadata in onUploadCreate
in a way that's persisted in the store too. We may want to support that at some point.
from tus-node-server.
Once the upload is completed I create an entry for it, that includes the unique ID, in a separate database.
I'd be happy to share the code that I wrote to make the changes to the upload
object persistent or even make a pull request if you think it'd help.
I've got it down to just adding two lines and changing two lines in the tus-node-server/packages/server/src/handlers/PostHandler.ts
file.
The main issue with my approach is that the changes do not persist all the way back to the client (which isn't necessary in my case, but still).
from tus-node-server.
Once the upload is completed I create an entry for it, that includes the unique ID, in a separate database.
Can't you just validate the upload in onUploadCreate
, reject if needed, and only create and store the ID in onUploadFinish
without the need to communicate between hooks?
from tus-node-server.
I would, but the ID is created as part of the validation process.
I'll just create a fork for myself with those small changes I mentioned, it should be simple to keep up to date with the main repo.
That said, would you like me to create a pull request with those changes?
The way it works is that the onUploadCreate
function returns both the res
object and the upload
object to the PostHandler
which then overwrites the upload
object in that file same as the res
object.
I'm not sufficiently familiar with the whole codebase to be sure that that's the best way to do it, what do you think?
from tus-node-server.
For reference, here is the updated code:
let upload = new models_1.Upload({
id,
size: upload_length ? Number.parseInt(upload_length, 10) : undefined,
offset: 0,
metadata,
});
if (this.options.onUploadCreate) {
try {
const afterUploadCreate = await this.options.onUploadCreate(req, res, upload);
res = afterUploadCreate[0];
upload = afterUploadCreate[1];
}
catch (error) {
log(`onUploadCreate error: ${error.body}`);
throw error;
}
}
from tus-node-server.
Here is the fork: https://github.com/sammibajrami/tus-node-server
from tus-node-server.
No problem, thank you for taking the time to help me!
While I'm sure that there is a smoother way to do this, here is updated code that only overwrites upload.metadata, while also being backwards compatible:
let upload = new models_1.Upload({
id,
size: upload_length ? Number.parseInt(upload_length, 10) : undefined,
offset: 0,
metadata,
});
if (this.options.onUploadCreate) {
try {
const afterUploadCreate = await this.options.onUploadCreate(req, res, upload);
res = afterUploadCreate[0];
if (afterUploadCreate[1]) {
upload.metadata = afterUploadCreate[1].metadata;
}
}
catch (error) {
log(`onUploadCreate error: ${error.body}`);
throw error;
}
}
from tus-node-server.
Related Issues (20)
- Track server-side upload progress HOT 2
- metdata example uses undefinded validateMetaData function HOT 1
- Demo for GCS incorrectly uses GCSDataStore HOT 3
- CRC errors using @google-cloud/storage 7.7.0 HOT 2
- Mixed content error - Page load over https buyt requested url is insecure HOT 1
- @tus/s3-store: Doesn't work with R2 HOT 1
- S3-store doen't work with Cloudflare R2 storage HOT 2
- Respect X-Forwarded-Port and X-Forwarded-Prefix as well HOT 2
- serverless integration HOT 1
- Upload fail after 10min request HOT 3
- Error installing 1.4.0 from npm HOT 2
- tus-node-server and ietf HOT 11
- Simultaneous file upload leads to corrupted files HOT 2
- Allow hooks to override metadata HOT 1
- Recommended nginx configuration HOT 2
- How to get final name back in client? HOT 4
- [S3Store] 0 bytes files are not uploaded HOT 1
- onUploadFinish should be able to alter response body HOT 5
- "Store files in custom nested directories" example fails with can't patch error HOT 10
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 tus-node-server.