From 23034ec145662b9edcd98df3a570e968389e3fa8 Mon Sep 17 00:00:00 2001 From: tobi <31960611+tsmethurst@users.noreply.github.com> Date: Sat, 19 Feb 2022 11:44:56 +0100 Subject: [feature] Stream files via reader (#404) * serve files via reader rather than byte slice * close readcloser when we're done with it * cast reader to readcloser --- internal/processing/media/getfile.go | 9 ++++++--- 1 file changed, 6 insertions(+), 3 deletions(-) (limited to 'internal/processing') diff --git a/internal/processing/media/getfile.go b/internal/processing/media/getfile.go index 0b818fd22..7431224c4 100644 --- a/internal/processing/media/getfile.go +++ b/internal/processing/media/getfile.go @@ -83,9 +83,11 @@ func (p *processor) GetFile(ctx context.Context, account *gtsmodel.Account, form switch mediaSize { case media.SizeOriginal: content.ContentType = e.ImageContentType + content.ContentLength = int64(e.ImageFileSize) storagePath = e.ImagePath case media.SizeStatic: content.ContentType = e.ImageStaticContentType + content.ContentLength = int64(e.ImageStaticFileSize) storagePath = e.ImageStaticPath default: return nil, gtserror.NewErrorNotFound(fmt.Errorf("media size %s not recognized for emoji", mediaSize)) @@ -101,21 +103,22 @@ func (p *processor) GetFile(ctx context.Context, account *gtsmodel.Account, form switch mediaSize { case media.SizeOriginal: content.ContentType = a.File.ContentType + content.ContentLength = int64(a.File.FileSize) storagePath = a.File.Path case media.SizeSmall: content.ContentType = a.Thumbnail.ContentType + content.ContentLength = int64(a.Thumbnail.FileSize) storagePath = a.Thumbnail.Path default: return nil, gtserror.NewErrorNotFound(fmt.Errorf("media size %s not recognized for attachment", mediaSize)) } } - bytes, err := p.storage.Get(storagePath) + reader, err := p.storage.GetStream(storagePath) if err != nil { return nil, gtserror.NewErrorNotFound(fmt.Errorf("error retrieving from storage: %s", err)) } - content.ContentLength = int64(len(bytes)) - content.Content = bytes + content.Content = reader return content, nil } -- cgit v1.2.3