Repository navigation
MVC loading from stream #21280
Replies: 1 comment
|
The request in your error shows two things going wrong at once:
Fix the first by encoding the file URL before putting it in the viewer's query string: For the second, either upgrade the viewer to 6.3.289 or later, or avoid a query string in the Since the viewer and the Action are on the same origin, the viewer's origin check |
Uh oh!
There was an error while loading. Please reload this page.
I have a frame on an mvc view which I want to load the contents from a stream I am getting thru an Action.
The Action code is this
[HttpGet]
public ActionResult DownloadShipmentLabel2(Int64 fileID, bool inline = false)
{
clsConsignmentFilesHelper myHelper = null;
string sErrorMessage = null, sFileName = null;
try
{
sFileName = clsDBFunctions.GetFieldFromKey("CR_Consignment_Files", "ID", fileID, "FileName", ConnectionString.GetConnectionString(clsDefaults.eCompanyFunctionality.FedEx)).ToString();
if (!string.IsNullOrWhiteSpace(sFileName))
{
string mimeType = System.Web.MimeMapping.GetMimeMapping(sFileName);
myHelper = new clsConsignmentFilesHelper(ConnectionString.GetConnectionString(clsDefaults.eCompanyFunctionality.FedEx));
byte[] buffer = myHelper.DownloadConsignmentFileToBytes(fileID, "FedEx", out sErrorMessage);
if (buffer != null)
{
MemoryStream stream = new MemoryStream(buffer);
if (inline)
Response.AddHeader("Content-Disposition", $"inline; filename={sFileName}");
else
Response.AddHeader("Content-Disposition", $"attachment; filename={sFileName}");
Then I have the following script to fill the frame with the pdf contents
function printConsignmentFile(fileID) {
const iframe = document.getElementById('viewer');
}
but I keep getting the following error in fetch_stream.js function fetchUrl
GET http://localhost:30114/fedex/DownloadShipmentLabel2%3FfileID%3D1316333 400 (Bad Request).
The url is fine cause when it is not inline the file is downloaded.
Can someone please help?
Thanks
Ivan
All reactions