Comments (5)
Im trying with your solution but I have a problem. Model is always null. Only image file was read correctly. This is post request which is send from my video camera after license plate is recognized:
POST /alpv/receive.php HTTP/1.1\r\n Host: 10.13.24.13\r\n Content-Length: 7160\r\n Content-Type: multipart/form-data; boundary=------------------------3df4e8eee91da308\r\n --------------------------3df4e8eee91da308 Content-Disposition: form-data; name="event"; filename="20190204103017_10536event_7000175.json" Content-Type: application/octet-stream { "packetCounter":"7000175", "datetime":"20190204 103017000", "plateText":"\u004c\u0042\u0045\u0033\u0039\u0037", "plateCountry":"SWE", "plateConfidence":"0.716159", "carState":"new", "geotag":{"lat": 50.418114,"lon": 30.476213}, "imageType": "plate", "plateImageType": "png", "plateImageSize": "0", "carMoveDirection":"in", "timeProcessing":"0", "plateCoordinates":[1614, 880, 172, 28], "carID":"18", "GEOtarget":"Camera", "sensorProviderID":"defaultID" } --------------------------3df4e8eee91da308 Content-Disposition: form-data; name="image"; filename="20190204103016_999776lp_LBE397_7000175.png" Content-Type: application/octet-stream <IMAGE DATA> --------------------------3df4e8eee91da308--
There are two files: "image" and "event".
In controller I write this:
public IActionResult NewEvent([ModelBinder(BinderType = typeof(JsonModelBinder))] DataFromCameraModel @event, IFormFile image) { return Ok(); }
and DataFromCameraModel
public class DataFromCameraModel { public int packetCounter {get;set;} public string Datetime {get;set;} public string plateText {get;set;} }
Hello.
I have the same problem.
Did you find a solution?
from jsonmodelbinder.
I solved as follows:
[HttpPost("newevent")]
[Consumes("multipart/form-data")]
public IActionResult NewEvent(IFormFile @event, IFormFile image)
{
using (var reader = new StreamReader(@event.OpenReadStream()))
{
eventmodel = JsonConvert.DeserializeObject<DataFromCameraModel>(reader.ReadToEnd());
}
firstchar = eventmodel.plateText[0];
if (eventmodel.plateText.Length == 7 && !Char.IsDigit(firstchar))
{
var imagepath = _truckService.UploadNewEventImage(image);
_truckService.SaveNewEvent(eventmodel,imagepath);
this.HubContext.Clients.All.SendAsync("Refresh", eventmodel);
}
return Ok();
}
public class DataFromCameraModel
{
public string Datetime { get; set; }
public string plateText { get; set; }
}
from jsonmodelbinder.
I solved as follows:
[HttpPost("newevent")] [Consumes("multipart/form-data")] public IActionResult NewEvent(IFormFile @event, IFormFile image) { using (var reader = new StreamReader(@event.OpenReadStream())) { eventmodel = JsonConvert.DeserializeObject<DataFromCameraModel>(reader.ReadToEnd()); } firstchar = eventmodel.plateText[0]; if (eventmodel.plateText.Length == 7 && !Char.IsDigit(firstchar)) { var imagepath = _truckService.UploadNewEventImage(image); _truckService.SaveNewEvent(eventmodel,imagepath); this.HubContext.Clients.All.SendAsync("Refresh", eventmodel); } return Ok(); } public class DataFromCameraModel { public string Datetime { get; set; } public string plateText { get; set; } }
Thanks for the reply.
So you did not actually use "JsonModelBinder"!
from jsonmodelbinder.
didnt use, you can get data easily with this:
using (var reader = new StreamReader(@event.OpenReadStream()))
{
eventmodel = JsonConvert.DeserializeObject<DataFromCameraModel>(reader.ReadToEnd());
}
from jsonmodelbinder.
didnt use, you can get data easily with this:
using (var reader = new StreamReader(@event.OpenReadStream())) { eventmodel = JsonConvert.DeserializeObject<DataFromCameraModel>(reader.ReadToEnd()); }
Thank you. ok.
from jsonmodelbinder.
Related Issues (10)
- Does the JsonModelBinder work with dot net core 2 HOT 3
- Kestrel 400 multipart body length limit
- Can you support .NetStandard 2.0?
- Bad namespace Microsoft.AspNetCore.Mvc.ModelBinding HOT 1
- Data Model Validation HOT 1
- If one parameter is empty, returning 500 HOT 2
- Code bug
- Support `System.Text.Json` in ASP.NET Core 3.0 apps
- Optional model validation
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
D3
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
-
Recommend Topics
-
javascript
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
-
web
Some thing interesting about web. New door for the world.
-
server
A server is a program made to process requests and deliver data to clients.
-
Machine learning
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from jsonmodelbinder.