i need upload any file vedio,image and doc by api from client to server This code works for me, but for files smaller than 2MB I can't download files up to 10 , 20MB I tried to change the code and style I also converted it to a byte[] and split it into several files, but it didn't work Please Help
this code for client
uri = new Uri(WebAPIUrl + "setimg/");
try
{
var content = new MultipartFormDataContent();
if(mediafile!=null)
{
var streamContent = new StreamContent(mediafile);
streamContent.Headers.Add("Content-Type", "application/octet-stream");
content.Add(streamContent, "\"img\"", $"\"{mediafile.Name}\"");
}
string json = JsonConvert.SerializeObject(u);
StringContent content1 = new StringContent(json, Encoding.UTF8, "application/json");
content.Add(content1, "value");
bool fin = false;
do
{
fin = true;
var response = await client.PostAsync(uri, content);
if (response.IsSuccessStatusCode)
{
var result = await response.Content.ReadAsStringAsync();
try
{
var Items = JsonConvert.DeserializeObject<List<string>>(result);
return Items;
}
catch
{
}
}
this code for server
public List<string> upload()
{
var httpRequset = HttpContext.Current.Request;
string imageslink = "";
if (httpRequset.Files.Count > 0)
{
foreach (string file in httpRequset.Files)
{
var postedfile = httpRequset.Files[file];
var filename = postedfile.FileName.Split('\\').LastOrDefault().Split('/').LastOrDefault();
// var filepath = HttpContext.Current.Server.MapPath("~/Uploads/" + filename);
imageslink += "D:\\casting\\" + filename + ";";
var filepath = "D:\\casting\\" + filename;
postedfile.SaveAs(filepath);
}
please help