Giter Club home page Giter Club logo

Comments (5)

o-medizadeh-Ard avatar o-medizadeh-Ard commented on July 30, 2024

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.

nmicun avatar nmicun commented on July 30, 2024

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.

o-medizadeh-Ard avatar o-medizadeh-Ard commented on July 30, 2024

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.

nmicun avatar nmicun commented on July 30, 2024

didnt use, you can get data easily with this:

 using (var reader = new StreamReader(@event.OpenReadStream()))
           {
             eventmodel = JsonConvert.DeserializeObject<DataFromCameraModel>(reader.ReadToEnd());
                
           }

from jsonmodelbinder.

o-medizadeh-Ard avatar o-medizadeh-Ard commented on July 30, 2024

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)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo 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.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.