I'm having problems trying to upload an attachment (for example, an image) with an input file, and send it via chat via SignalR, the problem is that it fails to serialize the formData, because it is not sent correctly the data, how could it be solved?
This is my code:
.aspx
var blobFile = $('#fuAdjuntos')[0].files[0];
var formData = new FormData();
formData.append("fuAdjuntos", blobFile);
chatHub.server.sendMessageToAll(userName, msg, date, idUsuario, $('#hdId').val(), null, formData );
.cs
public void SendMessageToAll(string userName, string message, string time, int idUsuario, string idChat, string usuarioDestinatario, object formData)
{
byte[] byteFile = datos.SerializarArchivo(formData);
Clients.All.messageReceived(userName, message, time, UserImg, usuarioDestinatario, byteFile);
}
public byte[] SerializarArchivo(object formData)
{
byte[] byteFile = null;
if (formData != null)
{
BinaryFormatter bf = new BinaryFormatter();
using (MemoryStream ms = new MemoryStream())
{
bf.Serialize(ms, formData);
byteFile = ms.ToArray();
}
}
return byteFile;
}