Closed Code-N-K closed 5 years ago
Hi @Code-N-K ,
I've just released 2.0.2
with a couple bug fixes, and now when an error occurs while uploading a file the state of the file upload input gets reset.
If you want to validate for file extensions, you could do so now on your file processing API.
There is no way at the moment to capture the error and show a message to the user or a toast notification. I believe the best way to tackle this would be to add another method to the file upload interface so you can supply your implementation of what to do when an error occurs.
I am considering a change on the main adapter and see if I can update it from being an abstract class to an interface, if so I'll include the changes for the file upload adapter on the same release.
I have added some code updates to file processing api.
public async Task
if (file.Length > 0)
{
using (var stream = new FileStream(filePath, FileMode.Create))
{
await file.CopyToAsync(stream);
}
}
var baseUri = new Uri($"{Request.Scheme}://{Request.Host}{Request.PathBase}");
var fileUri = new Uri(baseUri, $"Uploads/{file.FileName}");
return Ok(new
{
type = 2, // MessageType.File = 2
//fromId: ngChatSenderUserId, fromId will be set by the angular component after receiving the http response
toId = userId,
message = file.FileName,
mimeType = file.ContentType,
fileSizeInBytes = file.Length,
downloadUrl = fileUri.ToString()
});
}
else
{
//return BadRequest(new { message = "Invalid file." });
return Ok(new
{
type = 0,
toId = "",
message = "Invalid file.",
mimeType = "",
fileSizeInBytes = "",
downloadUrl = ""
});
}
}
else
{
//return BadRequest(new { message = "Invalid file size, only 2MB allowed." });
return Ok(new
{
type = 0,
toId = "",
message = "Invalid file size, only 2MB allowed.",
mimeType = "",
fileSizeInBytes = "",
downloadUrl = ""
});
}
}
else
{
//Return bad request//Should be Update
/*
return Ok(new
{
type = 0,
toId = "",
message = "no file",
mimeType = "",
fileSizeInBytes = "",
downloadUrl = ""
});
*/
if (userId == null)
{
//return BadRequest(new { message = "userid not available." });
return Ok(new
{
type = 0,
toId = "",
message = "userid not available.",
mimeType = "",
fileSizeInBytes = "",
downloadUrl = ""
});
}
else
{
//return BadRequest(new { message = "No file available." });
return Ok(new
{
type = 0,
toId = "",
message = "No file available.",
mimeType = "",
fileSizeInBytes = "",
downloadUrl = ""
});
}
}
}
Hi @Code-N-K ,
Please read my detailed message above. There isn't support at the moment and I will investigate adding an event raised method to the file upload adapter contract.
I always encourage everyone to contribute to ng-chat so feel free to contribute to the main repository too with pull requests. Just make sure we discuss and detail the design for new features as we need to consider many use case scenarios for other people using ng-chat.
Cheers!
Hi @Code-N-K ,
Please read my detailed message above. There isn't support at the moment and I will investigate adding an event raised method to the file upload adapter contract.
I always encourage everyone to contribute to ng-chat so feel free to contribute to the main repository too with pull requests. Just make sure we discuss and detail the design for new features as we need to consider many use case scenarios for other people using ng-chat.
Cheers!
Thats what i have written the code for my use, You need to add the above in upload File Method of Home controller in your code.
Thanks. @rpaschoal .
If Possible kindly provide code updates for Video Button Issue, as i received no reply for shared issue: https://github.com/rpaschoal/ng-chat/issues/116
As file upload is used how can we stop file loader if any invalid response is their, and how to validate the response in UploadFile of Homecontroller. @rpaschoal
As a use-case i dont want to upload zip,exe,rar on any restricted format.