https://github.com/danielearwicker/bytearrayformatters
Simple mapping between entire HTTP payload and [FromBody] byte[] parameter or return value.
https://github.com/danielearwicker/bytearrayformatters
Last synced: 8 months ago
JSON representation
Simple mapping between entire HTTP payload and [FromBody] byte[] parameter or return value.
- Host: GitHub
- URL: https://github.com/danielearwicker/bytearrayformatters
- Owner: danielearwicker
- License: mit
- Created: 2017-07-02T11:38:02.000Z (almost 9 years ago)
- Default Branch: master
- Last Pushed: 2018-10-13T21:04:19.000Z (over 7 years ago)
- Last Synced: 2025-03-26T15:48:00.550Z (about 1 year ago)
- Language: C#
- Size: 4.88 KB
- Stars: 2
- Watchers: 1
- Forks: 1
- Open Issues: 1
-
Metadata Files:
- Readme: README.md
- License: LICENSE
Awesome Lists containing this project
README
# ByteArrayFormatters
Simple mapping between entire HTTP payload and `[FromBody] byte[]` parameter or return value.
## Background
https://stackoverflow.com/questions/44090784/unsupported-media-types-when-post-to-web-api/44823478
## Usage
Install the package to your project:
Install-Package Earwicker.ByteArrayFormatters
Get access to the namespace:
```csharp
using Earwicker.ByteArrayFormatters;
```
Configure MVC in your `ConfigureServices` method:
```csharp
services.AddMvc(options =>
{
options.InputFormatters.Add(new ByteArrayInputFormatter());
options.OutputFormatters.Add(new ByteArrayOutputFormatter());
});
```
You can now use the `[FromBody]` attribute on controller method parameters of type `byte[]`:
```csharp
[HttpPut("files/{*path}")]
public void PutFile(string path, [FromBody] byte[] content)
{
...
}
```
You can also return `byte[]` from a controller method. The byte array takes up the entire payload of the HTTP request or response.