I am building dotnetcore 6 mvc project. In this project, I get files from API in byte[] format and return to razor view. Code here:
public IActionResult PreviewFile(int fileId)
{
var fileResult = _wrapper.Get<ApiDataResult<FilePreviewResponse>>($"{ApiUrls.FilePreviewGetById}{fileId}"); // this is where i get the file in byte array
fileResult.Wait();
if (fileResult.Result?.Success == true)
{
return Json(new
{
FileBytes = fileResult.Result.Data.FileBytes,
Extention = fileResult.Result.Data.Extention
});
}
In my razor view:
previewFileModal.show();
$.ajax({
method: "GET",
url: "/FileManagement/PreviewFile?fileId=" + fileId,
success: function (res) {
var bytes = _base64ToArrayBuffer(res.fileBytes);
var blob = new Blob([bytes], { type: res.extention });
var url = URL.createObjectURL(blob);
$("#PreviewFileFrame").attr('src', url);
},
error: function (xhr) {
}
});
In the razor view code, I can show pdf files. But not office files.
Can you help me how to do it?
I need just to convert office ArrayBuffer to pdf ArrayBuffer.
NOTE: I do not want to use any file path. It is forbidden.