IFormFile/StreamPart in shared model library #2053
-
|
Has anyone come up with a good method for sharing models that take IFormFile/StreamPart? |
Beta Was this translation helpful? Give feedback.
Answered by
glennawatson
Jun 16, 2026
Replies: 1 comment
-
|
The trick is to keep the shared model framework-agnostic and only adapt to the Refit/ASP.NET types at the edges. Things to know:
Recommended layout:
// shared model project (no Refit, no ASP.NET)
public sealed record UploadRequest(Stream Content, string FileName, string ContentType);
// client project (references Refit)
public interface IFilesApi
{
[Multipart]
[Post("/files")]
Task Upload([AliasAs("file")] StreamPart file);
}
// adapter, client side
var part = new StreamPart(req.Content, req.FileName, req.ContentType);
await api.Upload(part);
Bottom line: share Stream/byte[] + metadata strings, and convert to StreamPart (client) or from IFormFile (server) only in the projects that actually reference those frameworks. |
Beta Was this translation helpful? Give feedback.
0 replies
Answer selected by
glennawatson
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
The trick is to keep the shared model framework-agnostic and only adapt to the Refit/ASP.NET types at the edges.
Things to know:
Recommended layout: