I am using TelerikUpload control for file Upload. I am able to upload and download file without any issue. Currently for download when I click on download its downloading the file to Download folder. Instead of downloading, I want the file to be opened in a new browser tab without downloading. Any help on how this can be achieved. Please see my below code.
//Razor file
<script type="text/javascript">
function downloadAttachment(filename, content, mimeType) {
var blob = new Blob([content], { type: mimeType });
var link = document.createElement('a');
link.href = window.URL.createObjectURL(blob);
link.download = filename;
link.click();
window.URL.revokeObjectURL(link.href);
}
</script>
<TelerikButton @onclick="() => AttachmentDownload(item)">Download</TelerikButton>
//Razor.cs file
private async Task AttachmentDownload(Attachment attachment)
{
var extension = Path.GetExtension(attachment.fileName);
var mimeType = MimeTypeHelper.GetMimeType(extension);
byte[] ByteArray = FileStorage.ReadFile(attachment.Path);
if (ByteArray != null)
{
await JSRuntime.InvokeVoidAsync("downloadAttachment", attachment.fileName, ByteArray, mimeType);
}
}
public static string GetMimeType(string extension)
{
switch (extension)
{
case ".pdf":
return "application/pdf";
case ".csv":
return "text/csv";
case ".txt":
return "text/plain";
default:
return "application/octet-stream";
}
}