Skip to content
Discussion options

You must be logged in to vote

Use a Multipart method with one of the part wrapper types. Refit handles building the multipart content for you.

public interface IUploadApi
{
    [Multipart]
    [Put("/images/2023/temp.jpg")]
    Task Upload([AliasAs("file")] StreamPart stream);

    // or for a byte[]
    [Multipart]
    [Put("/images/2023/temp.jpg")]
    Task Upload([AliasAs("file")] ByteArrayPart bytes);
}

Call it:

await api.Upload(new StreamPart(stream, "temp.jpg", "image/jpeg"));
// or
await api.Upload(new ByteArrayPart(buffer, "temp.jpg", "image/jpeg"));

If you do NOT want multipart and instead want the raw body to be the file bytes/stream (matching your ByteArrayContent / StreamContent example), pass a Stream or b…

Replies: 1 comment

Comment options

You must be logged in to vote
0 replies
Answer selected by glennawatson
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Category
Q&A
Labels
None yet
2 participants