0

Actually i have created one page with text and image saving process to database. So i have used form-data. Everything is fine but when we give text with spaces, the spaces changed to '+' symbol. Please find below code for how i tried,

Script :

var fileData = new FormData();
var notes = "testing testing testing testing testing testing testing te";
fileData.append('notes', notes);
 $.ajax({
                url: "api/update",
                type: "POST",
                data: fileData,
                },
                success: function (response) {
                    alert("saved");
                }
});

I can get same string while debug Script. But after we posted from script to Action only i can get string as "testing+testing+testing+testing+testing+testing+testing+test".

C# :

[HttpPost]
[Route("api/update")]
public async Task<dynamic> PostAsyncOccupantImage()
{
      string error = string.Empty;
      MyStreamProvider streamProvider = new MyStreamProvider();
      await Request.Content.ReadAsMultipartAsync(streamProvider);
      var notes = streamProvider.FormData.ToString().Split('&')[0]
      return error;
}

Please give your suggestion. Thanks, Arun D

Arun D
  • 279
  • 3
  • 18
  • https://stackoverflow.com/a/11447443/5233656 you can refer from here – Mark Oct 06 '17 at 09:47
  • We have no idea what the heck `MyStreamProvider` is or where it gets its data or what it does with that data. – Sam Axe Oct 06 '17 at 09:54
  • No, instead of your given link i can replace '+' as ' ' in Method. I need to know why its happen and how its resolve @Mark – Arun D Oct 06 '17 at 09:56

1 Answers1

1

It is explained in the answer of the link that Mark gave:

In some GET and POST requests (most likely in the URL, or via a form), spaces are encoded as "+" (plus) symbols before they are passed to the server.

This is because URLs cannot contain spaces.

Note: this only goes for application/x-www-form-urlencoded content. The space character is otherwise encoded to this: %20.

Abbas
  • 14,186
  • 6
  • 41
  • 72