-
Notifications
You must be signed in to change notification settings - Fork 1
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
ngDownloadResponse not working #1
Comments
So the first thing I noticed, you are calling
, but declaring it with two.
I don't think you need to pass FYI: Here is some info about formatting things on Github. Use "Preview" tab before commenting :) |
Actually, I forgot to remove that. In my code I do have the 3 parameters for getfile, but removed e from the function params. It passes undefined. |
If that's the case, I don't see anything wrong with how you use the directive. Lets try to debug what's happening. Use Chrome for this debugging. Let's see why methods 1 or 2 aren't working in Chrome... |
IN IE, in savemethod1, on line 19, it throws an error InvalidStateError |
Meant to add, it looks like something is being returned in 64 byte encoding This may be why I am prompted in FF to save the file, but when I open it it is corrupted |
so some sort of data is returned, but the directive fails to instantiate |
Looks like the server is in fact returning the pdf. Took this from fiddler. HTTP/1.1 200 OK %PDF-1.3 �� |
So we are back to looking into why it breaks on line 19, in savemethod1, using this data..... |
yeah, it does look like a pdf. |
will do, while I wait, would this have anything to do with it...search for InvalidStateError |
K, here is the data written out to the console |
config
data
0
ParameterID
ParameterValue
1
ParameterID
ParameterValue
2
ParameterID
ParameterValue
headers
Accept
Authorization-Token
Content-type
method
responseType
transformRequest
0
transformResponse
0
url
data
status
statusText
headers
|
could you please show me |
var that = this;
}; |
{ }, |
the above is the data object formatted properly.... |
It appears that the data object is the request object isn't it? Shouldn't it be part of the response |
I think I found the problem. Data is a wrapper for the whole response and not just the 'data' that is returned. On line 96 I added the following line: var processData = data.data; However, in FireFox, no prompt comes up to save a pdf and in the console I see the following [14:29:26 GMT-0600 (Mountain Standard Time)] Browser Link: Failed to match method call MadsKristensen.EditorExtensions.BrowserLink.PixelPushing.PixelPushingModeFactory.setPixelPusingMode |
This is exactly what I was thinking. The Anyway, the error that you are getting in FF seems to be unrelated to ngDownloadResponse directive. There are no methods there called |
Did some more digging and in FF, the arraybuffer is empty in data.data...and yes, I did some research and setVisibility or setPixelPusingMode are not related to the issues we are having... So what do you think the solution is then. Everything works fine in Chrome and IE with data.data, but not in FF. |
not sure if this is related, but I usually put this line of code in the
What is the value of |
I'm unable to delete an headers unfortunately....as mentioned two comments up, data.data is an empty arraybuffer in FF. So the stream may be somewhere else within data. Are you able to investigate? |
I have tested the directive on Chrome, IE, and FF on my side. It works as expected. |
ok, were you working with a stream or pulling a pdf sitting on a server? |
I was working with a stream. Though I used sockets instead of $http. Here is my function to get data: $scope.getPdf = function () {
var deferred = $q.defer();
socket.emit('getPdf', $scope.args, function(response) {
if (response != false) {
deferred.resolve(response);
} else {
deferred.reject();
}
});
return deferred.promise;
} |
Thanks for that...Ill try it out in the morning...did you use a library for the socket? Ive not worked with sockets before From: Dmitry A. Efimenko [email protected] I was working with a stream. Though I used sockets instead of $http. Here is my function to get data: $scope.getPdf = function () { Reply to this email directly or view it on GitHubhttps://github.com//issues/1#issuecomment-99270927. |
I'm not suggesting you switching to sockets just to solve this issue. It was just an example of the code that showed how I handled returning a promise. You could try something similar for your $http: $scope.getPdf = function () {
var deferred = $q.defer();
$http.post('getPdf', $scope.args)
.success(function(response){
deferred.resolve(response);
})
.error(function(){
deferred.reject();
});
return deferred.promise;
} |
I was digging around today, and using Fiddler, and I noticed that $http gets called twice in FF, but only once in Chrome and IE. It looks like the first call is cancelled by the second call, but the promise returned from the first call is handled by your directive....in the second call, the arraybuffer is populated and has a length. The promise that is handled by the directive, the arraybuffer has a bytelength of zero. Ever run into anything like this? Terry Slack From: Dmitry A. Efimenko [email protected] I'm not suggesting you switching to sockets just to solve this issue. It was just an example of the code that showed how I handled returning a promise. You could try something similar for your $http: $scope.getPdf = function () { Reply to this email directly or view it on GitHubhttps://github.com//issues/1#issuecomment-99543682. |
I did some research and it looks as though this has been an issue with a get. I'm using a post |
That seems to be a very old issue (2013). Make sure to use latest angular. Could you show me the whole html element which uses the directive? |
we are using the latest angular v1.3.15. I'm not sure how to do the markup for the html in here. Also, this is why I want the event passed in in order to test if e.preventDefault can not only prevent our router from being called, but perhaps FF is treating it as being clicked twice. I will email you the markup to take a look at |
Here is one anchor that I use to call for a pdf. I have two others which will call excel or word. They are all marked up the same. At thsi time, $event does not get injected into the getFile method. |
I have issued a pull request regarding the use of the event object in the getHandler method. In my case, I found that I needed it to prevent a default route from being triggered, when downloading a pdf. It's my first pull request, I see I can merge it automatically, however I will wait until I hear back from you regarding this. Strangely enough, doing a reboot seemed to solve my problem, as I was able to download PDF, Excell and Word docs using your directive. Thanks for the help and the directive. From: Dmitry A. Efimenko [email protected] That seems to be a very old issue (2013). Make sure to use latest angular. Could you show me the whole html element which uses the directive? Reply to this email directly or view it on GitHubhttps://github.com//issues/1#issuecomment-99552130. |
To avoid issues with angular trying to navigate to other routes try using a <button type="button" class="btn btn-link"
download-backup-url="/Reports/Report/{{report.reportID}}"
download-error=" getfileerror()"
download-name="{{report.reportName}}.pdf"
download-mime="application/pdf"
download-response="getFile(report.reportID, 3)">PDF
</button> Couple things to notice here:
|
could we have an option for the event object so we aren't limited to using buttons? |
try editing line 83 of the directive to:
and add right after:
Let me know if this works for your scenario. |
It does work...did that originally, but then decided to add to the getHandler method because their are other things you could do technically with the event object. |
I'm having a problem getting the directive to work. To start, I am only using modern versions of FF, Chrome and IE 11. I've included it in the project as per the instructions on github. I've added markup to the html, and added a method to the $scope, within a controller. I can see the encoded response coming back from the server, however in FF, It prompts me to download a corrupt PDF. In Chrome, and IE, nothing happens and there isn't an error. In fact in Chrome and IE, the code jumps to savemethod3 each time. This will open a window and give me a 404. A pdf isn't generated and stored on the server, so the fall back method isn't going to work. I'm wondering, do I have to add responseType: "arraybuffer" to the request....? Is this something that could be built into your directive? And in the markup, you will notice, that I request $event to be the first paramter in getFile, however it is not injected by Angular. I'm wondering if you could also inject the $event. In IE 11, afterwards, the click is treated as an event and it's sent the default route is triggered, resulting in our, case, nothing being displayed on the page, as per the client request. At the bottom I've also included the headers seen in FireFox.
Any feedback is appreciated.
Here is the html markup:
"
Here is the code from the controller. I should add, it's written in typescript.
$scope.getFile = function (id, fileType): ng.IPromise{
//Build the reportUrl
var promise = undefined,
url = [that.apiBaseService.apiBase];
url.push("/Reports/RunReport/");
url.push(id);
url.push("?OutputFormat=");
url.push("3");
//catch the promise
promise = $http.post(
url.join(""),
that.serializeParameters(),
{ headers: { "Accept": "application/pdf" } });
};
//This is never hit if an error occurs
$scope.getFileError = (aaa,bbb,ccc,ddd,eee,fff,ggg)=> {
var mm = 0;
}
Access-Control-Allow-Orig... *
Access-Control-Expose-Hea...Accept,Origin,X-ProcuraGroup-OutputPageCount
Cache-Control no-cache
Content-Disposition
inline; filename=report.pdf
Content-Length 0
Content-Type application/pdf
Date Tue, 05 May 2015 17:09:03 GMT
Expires -1
Pragma no-cache
Server Microsoft-IIS/8.0
X-AspNet-Version 4.0.30319
X-Powered-By ASP.NET
X-ProcuraGroup-OutputPage... 0
X-SourceFiles =?UTF-8?B?QzpcVXNlcnNcQWRtaW5cRG9jdW1lbnRzXFZpc3VhbCBTdHVkaW8gMjAxM1xQcm9qZWN0c1xNYWluXFByb2N1cmFHcm91cC5BcGlcUmVwb3J0c1xSdW5SZXBvcnRcOA
==?=
The text was updated successfully, but these errors were encountered: