question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

split upload directories

See original GitHub issue

hey guys…like the idea of tus and resumable uploads because connections are really sluggish here in perú at times…even wired connections 👍 even though at least the node server looks a little abandoned at the moment?!

am i correct that it used to support koa.js? does it still? and what version?

now to the topic, i’m splitting my upload directory in incremented folders [1, 2, 3, …] to reduce number of files in a single folder how can i do this using tus-node? how to create a new directory if specified limit reached? maybe checking file count on upload complete and then just passing new dir to fileServer.datastore.path ?

and I’m not yet sure how serving those files work…i can just serve them using koa of course but i try to understand tus and custom get handlers so right now opening the url of an uploaded file won’t do anything besides logging handle: GET /files/726e2c46be5fd77c4b8661f0a1cec62a

any input appreciated 😃

Issue Analytics

  • State:closed
  • Created 6 years ago
  • Comments:7 (3 by maintainers)

github_iconTop GitHub Comments

3reactions
SavePointSamcommented, Apr 4, 2018

For anyone that ends up here in the future curious about koa support. You’ll need to use the following as using koa-connect directly doesn’t work due to inconsistencies in how the Server#handle method works.

import Koa from 'koa'; // Koa v2.x
import koaCors from '@koa/cors';
import koaBody from 'koa-bodyparser';
import koaCompress from 'koa-compress';
import Router from 'koa-router';
import { Server, FileStore, EVENTS } from 'tus-node-server';

const SHARED_PATH_NAME = '/uploads';
const tusServer = new Server();

tusServer.datastore = new FileStore({
  path: SHARED_PATH_NAME,
});

tusServer.on(EVENTS.EVENT_FILE_CREATED, event => {
  console.log('a file was created!');
});

tusServer.on(EVENTS.EVENT_UPLOAD_COMPLETE, ({ file }) => {
  console.log('a file was uploaded!');
});

const handler = tusServer.handle.bind(tusServer);
const middleware = async (ctx, next) => {
  // set default status to 200 for tus as koa defaults to 404
  ctx.status = 200;

  await handler(ctx.req, ctx.res);
  await next();
};

const router = new Router().all(`${SHARED_PATH_NAME}/:tusId?`, middleware);

const server = new Koa()
  .use(koaCors())
  .use(koaBody())
  .use(koaCompress())
  .use(router.routes())
  .use(router.allowedMethods())
  .listen(8080, () => {
    console.log('Server now available on http://localhost:8080');
  });

It is also important to know that your API path and your FileStore path need to be the same! If they are different you’ll run into issues where the final PATCH will fail even though the file was successfully uploaded. I haven’t found a way around this or determined why it happens. Although, it seems like a bug to have a dependency like that.

1reaction
Acconutcommented, Sep 9, 2017

Sounds good 😃 I am going to close this issue now as it seems your questions are answered. Feel free to open a new issues if further problems arise.

Read more comments on GitHub >

github_iconTop Results From Across the Web

split-folders - PyPI
split -folders Build Status PyPI - Python Version PyPI - Downloads. Split folders with files (e.g. images) into train, validation and test (dataset)...
Read more >
How to split my uploaded media into directories?
1 Answer 1 · now...I need have the possibility to create subdirectory into my standard media directory, for example: "logos", "brochures", " ...
Read more >
How to Split a Large File into Multiple Smaller Pieces
First up, right-click the file you want to split into smaller pieces, then select 7-Zip > Add to Archive. Give your archive a...
Read more >
Split and Compress Large Files and Folders Automatically
How to split a big folder or file into small folders or files and compress into size ... Uploading large files and folders...
Read more >
How to split large folder into multiple folders [Full Guide]
To split a file or a zipped folder, go to Split Files Online and click on Choose File. · Browse and select the...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found