Getting file from .ashx with a jQuery Post - vb.net

This question is a following from another question I asked - Passing client data to server to create Excel or CSV File.
I have a client page which builds a JSON object to send to the server, and I have server code which can parse that JSON object into an SQL command and end up with a dataset of required data.
I had originally been passing the JSON object to an .asmx web service which would return a JSON object containing my data. Now I want to go in a different direction and have the data returned as a .csv file.
I understand I can try to put my JSON object into a query string and call my .ashx page, but the JSON object could get large, so I'm trying to use the Request.Form of a POST.
My question, and lack of understanding, is in how to use jQuery to post to the .ashx page and have it return the .csv file to the client. If I navigate to the .ashx page directly (and modify the page to hard code the passed data), I get the .csv file returned to me no problem (i.e I get the prompt to open/save the file). If I make a POST to the .ashx file from jQuery and send my JSON object through, I get a response which contains the data in a string, rather than getting a .csv.
So, is there something I am missing, or am I just trying to achieve something that I can't or shouldn't be doing?
I'd thought about passing my JSON object to a .asmx web service which would store the JSON object into a database and return an ID, and then use window.location to browse to the .ashx with the ID as a query string parameter to then generate the .csv file, but I thought there might be a way to avoid that middle step and do it with the POST.
Sorry if this is a little rambling and disjointed. I'll be happy to clarify on any parts that may not make sense to anyone.

I am trying to do something similar as we speak.
Take a look at this question. It might help you.
How to: jQuery post to ashx file to force download of result?

Related

Refference JSON schema from "define" API YAML file in Postman instead of creating a variable with actual JSON

I have an API in Postman that has defined JSON schemas for every request\response.
I also have a collection of tests that i use for testing this API.
But I don't know how to connect these two substances(things)
I have been searching for a solution for quite a while now and havent found an example set-up or a tutorial how? instead of creating a variable with actual schema in my test collection, I want to reuse already existing schema from API by $ref or some other link method.
This is my first question here, writing it just cause i haven't found a proper answer but functionality that i seek sounds really basic and logical.
Update from Valentin Despa:
"Please note that the API definition is written in a specification like Open API (or similar). It is not the same as the JSON schema which refers to the response body only."
So we can't validate response using that schema.

Simplest way/tool to automate API calls and to save Json results in a file?

What would be the simplest tool/editor (ideally for Mac) to run web API queries (Stateless RESTful web API) in a loop in order to store Json results in a file ?
Very simple basically, trying just to automate the following :
- a first call to get a list of IDs
- then for each each ID, doing a call to get a few values related to this ID. Values are returned in a Json file, I would like to store them in a file (csv or excel)
To test the queries, I've used "Advanced REST client" to set a request with my authentication information header and do a few API queries tests, it works well but now I basically want to create a script to get the whole set of data which is returned and save in a file. With the idea to run this script from time to time. You can't to that with "Advanced REST client", right?
Sorry it's not (yet!) a super advanced question but any help would be greatly appreciated.
You may try Postman - definitely works on (accursed) Mac

Multi-page document as images over REST (additional questions)

I read this question - Multi-page document as images over REST which has very nice answer. We have similar scenario but with some additional requirement.
The request can either return the document as binary data or upload the pdf/jpeg(s) somewhere and return a URL to the uploaded file.
How should the calls be different? What is coming to my mind is to use GET for the binary data response and POST when it uploads and returns URL. When it is POST it will return 201 (Created) and return the URL to the uploaded document.
There is also one more detail about the first point. When uploading and returning a URL we can either upload for a temporary usage (and delete it after some time) or make it permanent. Should we do this by adding query parameter? like - POST /documents/12345.pdf?permanent=true
As in the original question, we also return different jpeg for every page. But the process of creating the document is time consuming so we want to take all pages at one request. What would be the proper way of doing this? I think in the 201 response you can only return one URL.
Is the GET /documents/12345.pdf approach a good alternative of the accept header or there are also other approaches? Would using the slash instead of dot be better, like GET /documents/12345/pdf? This way it wouldn't be needed to parse the "12345.pdf" string.
Thanks!
I've learned a thing or two in the past two years lets see if I can take a stab at this...
You can make the POST request always return the URI of the newly created resource. Do you ever need the POST to return the binary if you're the one providing it in the first place? I think I'm tracking with you in this case the GET would return the binary and the POST would create the resource and return the location (URI) of the newly created resource.
This isn't RESTful as GETs should be safe (GETs don't modify resources). You could make it a PUT if you want to update the status after the fact or when you POST you could add a flag in the request body to mark it should be permanent. Info on POSTing an image and data can be found here
For #3 do you want to fetch or upload everything in one request? You can return whatever you want in the response. You could structure your request in such a way to return a json array of urls. For example if you structure your request similar to my example then GET /documents/12345/1 may return page 1 of document 12345 while GET /documents/12345 may return all pages to document 12345.
For #4 I wouldn't do /pdf as that represents resource hierarchy. PDF is only the representation of the document, not the actual document. I would vote querystring since there may be other attributes. For example imagine trying to do the following with slashes... GET /documents/12345?format=pdf&color=grayscale&quality=300dpi&layout=portrait

How to streamline an SSRS web service call?

Using a 3rd party application (Tenfold) I currently call the SSRS web service methods to render a report as .pdf.
After I receive the encoded blob (5th parameter in the Render Method) I write the blob to the file system as a pdf using an internal WriteBinaryFile call, but in this form I cannot open it in a pdf reader. To solve this problem we write a .txt file with the path and file name of the pdf. Then send that to an external program Base64Decoder.exe which converts the file to a user friendly form that I can then open and view properly.
The Base64Decoder.exe is not 100% reliable and I'm looking for a better way to solve this problem. From what I've read from others the web service should return the blob in binary form which I then should be able to open without any conversion. Thanks in advance for any light that you can shed on this issue for me.
the render method returns a byte array, which is what you want to save to disk
there's an example here:
http://technet.microsoft.com/en-us/library/aa258532(v=sql.80).aspx

I am using the fine uploader plugin and having trouble using the delete file feature after upload

Base on their document http://blog.fineuploader.com/2013/01/25/delete-an-uploaded-file-in-3-3/, there is the UUID of the file to be deleted sent server with teh delte request.
But I have been trying the whole day and i cant get it to work.
For example here is a UUID of a file "1a2c636f-04f0-48c3-956f-22274a93b82f", i don't know how to use this to delete a the file. Should it be decrypted with some form of function first.
This might be a simply thing, but i don't know how to do it.
Thank you for your help in advance.
The UUID for a file is passed along with each request. You must associate this UUID with the actual file server-side. When the DELETE request comes in, find the file associated with the passed UUID, delete it, and return a 200 response.
Looking at the server-side readme again, I realize that the presence of this parameter in each request is probably not documented very well. I just updated the documentation to add another reference to this parameter.