public Product products = new Product();
List<fileInfo> files = new List<fileInfo>();
public class fileInfo
{
public string Path { get; set; }
public string Name { get; set; }
public double Size { get; set; }
}
public void OnChangeUpload(UploadChangeEventArgs args)
{
foreach (var file in args.Files)
{
var pathToSave = Path.Combine(Directory.GetCurrentDirectory(), "Images");
var fullPath = Path.Combine(pathToSave, file.FileInfo.Name);
byte[] bytes = file.Stream.ToArray();
string base64 = Convert.ToBase64String(bytes);
files.Add(new fileInfo() { Path = @"data:image/" + file.FileInfo.Type + ";base64," + base64, Name = file.FileInfo.Name, Size = file.FileInfo.Size });
}
} |
public void HandleValidSubmit()
{
Console.WriteLine(files);
} |
Trying to save file path to database through a service and controller
public async Task<int> CategoryInsert(string CategoryName, string CategoryImage)
{
var response = await _httpClient.PostAsJsonAsync($"api/Category/categoryinsert/{CategoryName}/{CategoryImage}", CategoryImage );
var contents = await response.Content.ReadAsStringAsync();
return Convert.ToInt32(contents);
}
but I get an error "Unhandled exception rendering component: Invalid URI: The Uri string is too long."
saving the CategoryImage as any other string works but saving the base64 string gives the error
How do I resolve this?
Below is my controller
// POST api/<CategoryController>
[HttpPost]
[Route("categoryinsert/{CategoryName}/{CategoryImage}")]
public async Task<int> CategoryInsert(string CategoryName, string CategoryImage)
{
int Success = 0;
var parameters = new DynamicParameters();
parameters.Add("@CategoryName", CategoryName, DbType.String);
parameters.Add("@CategoryImage", CategoryImage, DbType.String);
parameters.Add("@ReturnValue", dbType: DbType.Int32, direction: ParameterDirection.ReturnValue);
using IDbConnection conn = new SqlConnection(_configuration.GetConnectionString(connectionId));
{
// Stored procedure method
await conn.ExecuteAsync("spCategory_Insert", parameters, commandType: CommandType.StoredProcedure);
Success = parameters.Get<int>("@ReturnValue");
}
return Success;
}
You can refer to the below public forums for your requirement.