Click here to Skip to main content
15,896,111 members

Comments by Rohith Reddy Vadiyala (Top 14 by date)

Rohith Reddy Vadiyala 3-Oct-18 10:05am View    
we dont use any proxy. We have ADFS server and Hosted App server in different domains.
Rohith Reddy Vadiyala 3-Oct-18 8:57am View    
yes we have setup a ADFS serve which communicates with AD.
Rohith Reddy Vadiyala 30-Apr-15 8:52am View    
Deleted
Anjular code:
--------------------
var getFileDownloadData = function (dictName, inputParams) {
var deferred = $q.defer();

$http({
method: 'GET',
cache: false,
url: trideoConst.getUrl(dictName), // someurl/api/controller
headers: {
'Content-Type': 'application/json; charset=utf-8'
}
}).success(function (data, status, headers) {
debugger;

var octetStreamMime = 'application/octet-stream';
var success = false;

// Get the headers
headers = headers();

// Get the filename from the x-filename header or default to "download.bin"
var filename = headers['x-filename'] || 'download.txt';

// Determine the content type from the header or default to "application/octet-stream"
var contentType = headers['content-type'] || octetStreamMime;


// var _data = headers['x-sourcefiles'];

try {
// Try using msSaveBlob if supported
console.log("Trying saveBlob method ...");
var blob = new Blob([data], { type: contentType });
if (navigator.msSaveBlob)
navigator.msSaveBlob(blob, filename);
else {
// Try using other saveBlob implementations, if available
var saveBlob = navigator.webkitSaveBlob || navigator.mozSaveBlob || navigator.saveBlob;
if (saveBlob === undefined) throw "Not supported";
saveBlob(blob, filename);
}
console.log("saveBlob succeeded");
success = true;
} catch (ex) {
console.log("saveBlob method failed with the following exception:");
console.log(ex);
}

if (!success) {
// Get the blob url creator
var urlCreator = window.URL || window.webkitURL || window.mozURL || window.msURL;
if (urlCreator) {
// Try to use a download link
var link = document.createElement('a');
if ('download' in link) {
// Try to simulate a click
try {
// Prepare a blob URL
console.log("Trying download link method with simulated click ...");
var blob = new Blob([data], { type: contentType });
var url = urlCreator.createObjectURL(blob);
link.setAttribute('href', url);

// Set the download attribute (Supported in Chrome 14+ / Firefox 20+)
link.setAttribute("download", filename);

// Simulate clicking the download link
var event = document.createEvent('MouseEvents');
event.initMouseEvent('click', true, true, window, 1, 0, 0, 0, 0, false, false, false, false, 0, null);
link.dispatchEvent(event);
console.log("Download link method with simulated click succeeded");
success = true;

} catch (ex) {
console.log("Download link method with simulated click failed with the following exception:");
console.log(ex);
}
}

if (!success) {
// Fallback to window.location method
try {
// Prepare a blob URL
// Use application/octet-stream when using window.location to force download
console.log("Trying download link method with window.location ...");
var blob
Rohith Reddy Vadiyala 30-Apr-15 8:46am View    
Deleted
I'm trying to download pdf and doc files for now. They are able to download but cant be opened (like corrupt files).

Please help me where the issue is:

The following is the code in API controller:
--------------------------------------------
-> FileIOController

[HttpGet]
public HttpResponseMessage GetFileData([ModelBinder]List<string> inputparams)
{
var fileData = _fileUploadManager.GetFileData(3047);

if (fileData != null)
{
//return fileData;


HttpResponseMessage response = new HttpResponseMessage();
response.StatusCode = HttpStatusCode.OK;
response.Content = new ByteArrayContent(fileData.FileContent);
response.Content.Headers.ContentType = new MediaTypeHeaderValue("application/octet-stream");
response.Content.Headers.ContentDisposition = new ContentDispositionHeaderValue("attachment")
{
FileName = fileData.FileName
};
response.Content.Headers.ContentLength = fileData.FileContent.Length;
response.Content.Headers.Add("x-filename", fileData.FileName);
return response;
}
}


------------------------------------

angular JS Get Request
---------------------------

var getFileDownloadData = function (inputParams) {
var deferred = $q.defer();
//$http.get(http://sampleApi/api/FileIO,inputParams)
//$http.get(trideoConst.getUrl(dictName),
// { params: { '': inputParams } })
$http({
method: 'GET',
cache: false,
url: trideoConst.getUrl(dictName),
headers: {
'Content-Type': 'application/json; charset=utf-8'
}
}).success(function (data, status, headers) {
debugger;

var octetStreamMime = 'application/octet-stream';
var success = false;

// Get the headers
headers = headers();

// Get the filename from the x-filename header or default to "download.bin"
var filename = headers['x-filename'] || 'download.txt';

// Determine the content type from the header or default to "application/octet-stream"
var contentType = headers['content-type'] || octetStreamMime;


// var _data = headers['x-sourcefiles'];

try {
// Try using msSaveBlob if supported
console.log("Trying saveBlob method ...");
var blob = new Blob([data], { type: contentType });
if (navigator.msSaveBlob)
navigator.msSaveBlob(blob, filename);
else {
// Try using other saveBlob implementations, if available
var saveBlob = navigator.webkitSaveBlob || navigator.mozSaveBlob || navigator.saveBlob;
if (saveBlob === undefined) throw "Not supported";
saveBlob(blob, filename);
}
console.log("saveBlob succeeded");
success = true;
} catch (ex) {
console.log("saveBlob method failed with the following exception:");
console.log(ex);
}

if (!success) {
// Get the blob url creator
var urlCreator = window.URL || window.webkitURL || window.mozURL || window.msURL;
if (urlCreator) {
// Try to use a download link
var link = document.createElement('a');
if ('download' in link) {
// Try to simulate a click
try {
// Prepare a blob URL
console.log("Trying download link method with simulated click ...");
var blob = new Blob([data], { ty
Rohith Reddy Vadiyala 30-Apr-15 1:58am View    
do you have any sample data which is a response to success method??
Actually the problem is I could able to download a file (pdf) but while opening it throws error in adobe reader: - "there was an error opening this document. the root object is missing or invalid"