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

DownloadAttachment as Stream #152

Closed
emrecaglar opened this issue Nov 23, 2021 · 2 comments
Closed

DownloadAttachment as Stream #152

emrecaglar opened this issue Nov 23, 2021 · 2 comments
Labels
enhancement New feature or request

Comments

@emrecaglar
Copy link

A stream-returning method is required to access the file from memory without writing it to disk.

DownloadAttachmentAsync like

public async Task<Stream> DownloadAttachmentAsStreamAsync(CouchAttachment attachment, CancellationToken cancellationToken = default)
{
    Check.NotNull(attachment, nameof(attachment));

    if (attachment.Uri == null)
    {
        throw new InvalidOperationException("The attachment is not uploaded yet.");
    }

    return await NewRequest()
        .AppendPathSegment(attachment.DocumentId)
        .AppendPathSegment(Uri.EscapeUriString(attachment.Name))
        .WithHeader("If-Match", attachment.DocumentRev)
        .GetStreamAsync(cancellationToken)
        .ConfigureAwait(false);
}
@broomfn
Copy link

broomfn commented Nov 23, 2021

I'm not sure if it helps or not, but I wrote a method to return the data as bytes using Flurl:

return await mCouchDbOptions.Endpoint.WithBasicAuth(mCouchDbOptions.Username, mCouchDbOptions.Password)
.AppendPathSegment(databaseName)
.AppendPathSegment(Uri.EscapeUriString(document.Id))
.AppendPathSegment(Uri.EscapeUriString(attachmentName))
.WithHeader("If-Match", document.Rev)
.GetBytesAsync(cancellationToken);

@matteobortolazzo matteobortolazzo added bug Something isn't working enhancement New feature or request and removed bug Something isn't working labels Nov 23, 2021
@matteobortolazzo
Copy link
Owner

v3.2.0 Released

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement New feature or request
Projects
None yet
Development

No branches or pull requests

3 participants