Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Uploading a file directly from disk into tusd #947

Closed
torabian opened this issue May 27, 2023 · 1 comment
Closed

Uploading a file directly from disk into tusd #947

torabian opened this issue May 27, 2023 · 1 comment
Labels

Comments

@torabian
Copy link

Question
Thank you for all effort on this library.

I wonder, how can I upload a file into TUSD without a client. For CLI tools I create, now I need to upload a file from disk to TUSD, I want very similar flow so everything stays consistent.

I do not find any way about that, it seems every upload should go through http handler.

Many thanks

@Murderlon
Copy link
Member

Yes, you can if you use the package programatically. For example:

filestore := filestore.FileStore{Path: "./uploads"}
composer := tusd.NewStoreComposer()
filestore.UseIn(composer)
tus_store := composer.Core
ctx := context.Background()


upload, err := tus_store.NewUpload(ctx, handler.FileInfo{ Size: size }) // get size from somewhere
if err != nil {
	// ...
}
_, writeErr := upload.WriteChunk(ctx, 0, res.Body)
if writeErr != nil {
	// ...
}
finishErr := upload.FinishUpload(ctx)
if finishErr != nil {
	// ...
}

@Acconut Acconut closed this as completed Aug 23, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

No branches or pull requests

3 participants