C
C#5w ago
surwren

Can .NET controllers accept binary data? Should they?

I have already done EFcore mapping for - user - post - media Currently the client posts to server and COS separately. I was wondering if there was a way to streamline post creation, such that the client sends the media together with the db update (to the server), and then the server can do both the db upload and cos upload in a transaction of some sort? Is this possible or advised?
4 Replies
FestivalDelGelato
obviously controllers can accept binary data at most the point would be if the content is big such that it requires 10s of seconds or minutes to upload then you would need a retrying mechanism, and at that point a separate endpoint would be better if not net you can search for the usual ways, base64, mulitpart, and so on
greyfox
greyfox5w ago
Would want to make sure they're not doing something stupid like uploading an exe or a cshtml file that gets executed on the server when retrieved.
surwren
surwrenOP5w ago
what is the best way to accept image, video, and audio? I have done base64 transmission before via websockets but I don't know if .NET server is supposed to handle binary like this
FestivalDelGelato
you can do that from the ui, analyze the first bytes if you find a "denied" signature for the COS it depends what it is, some i believe have 'filters', if not you have to run your checks after upload is finished images and audios aren't usually that big, while videos can be GBs in general for content ingestion i would use a separate endpoint, although in the ui you can present it as one form/page if you want to do it fast probably the the less effort requiring way would be just put it in a base64 and send it if you are technically prepared and want to do a better product then chunk the binary data and add a retry mechanism for the chunks or you can also search for an uploader library to do it for you

Did you find this page helpful?