0

I have http get action that sends some user information from database, including small image(around 100kb) even thought I understand its not the best solution, I store it in byte[] and convert to base64string before sending it to view. This string is part of viewModel, I dont send it directly with url. When the length of the string is under 30k characters It does work, but as it goes near 100k i get exception: "Invalid URI: The Uri string is too long". How is my viewModel property bidden with uri length? And what can be possible workaround?

var viewModel = new UserViewModel(){ Image = Convert.ToBase64String(user.Image)}; return View(viewModel);

Any information would be much appreciated.

sneuly
  • 96
  • 1
  • 9
  • Use an HTTP POST instead and put the image in the body, that's what it's for. – Jon Apr 18 '17 at 14:33
  • But why does property of viewModel impact uri? – sneuly Apr 18 '17 at 14:52
  • Can you post what your URI looks like? – Jon Apr 18 '17 at 14:54
  • http://localhost:1234/User/Edit – sneuly Apr 18 '17 at 14:55
  • Did you tag your Action method with [HttpPost] ? The maximum length of a Uri is around 2000 characters (http://stackoverflow.com/questions/417142/what-is-the-maximum-length-of-a-url-in-different-browsers) – Jon Apr 18 '17 at 14:56
  • I know its gonna work that way, I'm curious why can't I send it using httpget? How is uri (http://localhost:1234/User/Edit) more than 2000? – sneuly Apr 18 '17 at 14:59
  • 2
    Because the Image property of your viewModel is returned in the URI e.g. http://localhost:1234/User/Edit?Image={randomHexStringHereThatsTooLong} – Jon Apr 18 '17 at 15:00
  • Yes, I figured it out, thanks. So, I have to use httppost or send image as some other type? – sneuly Apr 18 '17 at 15:05
  • Actually now that I think about it, I don't even know what I'm talking about. As long as the Image is not an argument into your action method it should not be in the URL. – Jon Apr 18 '17 at 15:08

0 Answers0