<SfUploader ID="UploadFiles" AutoUpload="false">
<UploaderEvents Success="OnSuccess"></UploaderEvents>
<UploaderAsyncSettings SaveUrl="api/SampleData/Save" RemoveUrl="api/SampleData/Remove"></UploaderAsyncSettings>
</SfUploader>
<p>key value is: @key</p>
<p>pair value is: @value</p>
@code{
public string customHeader { get; set; } = "";
public string key { get; set; } = "";
public string value { get; set; } = "";
public void OnSuccess(SuccessEventArgs args)
{
var customHeader = new string[] { };
customHeader = args.Response.Headers.Split(new Char[] { '\n' }); // To split the response header values
for (var i = 0; i < customHeader.Length; i++)
{
if (customHeader[i].Split(new Char[] { ':' })[0] == "id")
{
key = customHeader[i].Split(new Char[] { ':' })[0]; // To get the key pair of provided custom data in header
value = customHeader[i].Split(new Char[] { ':' })[1].Trim(); // To get the value for the key pair of provided custom data in header
}
}
}
} |
public async void Save(IList<IFormFile> UploadFiles)
{
try
{
foreach (var file in UploadFiles)
{
if (UploadFiles != null)
{
var filename = ContentDispositionHeaderValue.Parse(file.ContentDisposition).FileName.Trim('"');
filename = hostingEnv.WebRootPath + $@"\{filename}";
if (!System.IO.File.Exists(filename))
{
using (FileStream fs = System.IO.File.Create(filename))
{
file.CopyTo(fs);
fs.Flush();
}
}
else
{
Response.Clear();
Response.StatusCode = 204;
Response.HttpContext.Features.Get<IHttpResponseFeature>().ReasonPhrase = "File already exists.";
}
}
Response.Headers.Add("ID", "Updated");
}
} |
|
services.AddCors(options =>
{
options.AddDefaultPolicy(
builder =>
{
.AllowAnyMethod()
.AllowAnyHeader()
.AllowCredentials()
.WithExposedHeaders("*");
});
}); |