ASP.NET Core Web API byte[] issues

Hello there, I am trying to accept a byte array in my API request:
class X {
public byte[] Test { get; set; }
}
class X {
public byte[] Test { get; set; }
}
Swagger is used to test the API. When I launch the project and open it in my browser I see that this property accepts a string instead of a byte[]. Googling this issue did not gave much information besides this SO-thread https://stackoverflow.com/questions/77233543/call-an-api-with-byte-array-in-net-6 My question is if this is good enough or has anyone else faced similar issues?
Stack Overflow
Call an api with byte array in .NET 6
I am creating an ASP.NET Core 6 Web API. I did enable Swagger and would like to test an endpoint with input body of datatype byte[]. [HttpPost(Name = "publishdata")] public IActionResult ...
10 Replies
△ electronic heartbreak.
does this mean i need to send base64 strings anyway or? I wonder if sending images to an API is even good practice at all 😅
Pobiega
Pobiega2mo ago
its not, and if its done, its usually via a file upload.. or base64 you never really do [12,8,7,..] :d since the byte size of that is significantly larger than a base64 string
△ electronic heartbreak.
So just uploading a base64 string is the most senseful way to upload an image to the API?
Pobiega
Pobiega2mo ago
no I didn't say that
△ electronic heartbreak.
I mean there are more ways to get to Rome
Pobiega
Pobiega2mo ago
I'd use literal file upload, but yeah the second most common is probably base64 string
△ electronic heartbreak.
I will look on literal file upload tomorrow and compare it with the base 64
△ electronic heartbreak.
What I find hard about programming now is that when having my first job is making choices Since there are so many ways of implementing something and all have their pros and cons
Pobiega
Pobiega2mo ago
yup.
Want results from more Discord servers?
Add your server