diff options
author | 2022-02-19 11:44:56 +0100 | |
---|---|---|
committer | 2022-02-19 11:44:56 +0100 | |
commit | 23034ec145662b9edcd98df3a570e968389e3fa8 (patch) | |
tree | bb5678a1fae1c70a8a49b58ce17c5d51eae8710c /internal/processing/media/getfile.go | |
parent | Use type=email for email input (#400) (diff) | |
download | gotosocial-23034ec145662b9edcd98df3a570e968389e3fa8.tar.xz |
[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
Diffstat (limited to 'internal/processing/media/getfile.go')
-rw-r--r-- | internal/processing/media/getfile.go | 9 |
1 files changed, 6 insertions, 3 deletions
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 } |