Download file returned by ajax - ajax

I am showing file names in a gridView. I have used a link for the file name. When user clicks the filename the file should be downloaded. For this I used ajax in javascript to send parameters to controller.
In my controller action I am using code
readfile( Yii::getPathOfAlias('webroot.order files').DIRECTORY_SEPARATOR.$order->user_id.DIRECTORY_SEPARATOR.$_GET['id'].DIRECTORY_SEPARATOR.$_GET['file']);
Yii::app()->end();
But the result is returned as a string in response.
Is there a way to download file from the returned string? I know file cant be downloaded from the string, i am just asking some way to download file using ajax.

Related

How to send csv file or json data in post request in jmeter?

I have a post request naming 'Register' which will allow users to upload .csv files or .json files I want to test the load on this API with different CSV /JSON files for different users. I have added files path in 'PLAN.CSV' .Each file contain JSON DATA-
Please guide
Request image and result image is attached hereResquest
Response
CSV CONFIG SET
Your syntax is incorrect, the valid one for the __FileToString() function would be:
${__FileToString(${JSON_FILE},,)}
Consider using Functions Helper Dialog if you're uncertain
Your setup doesn't really "upload" the file, it sends the file as the HTTP POST body, the "upload" assumes either PUT or POST with multipart-form/data. Again if you're not sure that you're building the request correctly just record it using JMeter's HTTP(S) Test Script Recorder, just make sure that the file(s) you're uploading are present in "bin" folder of your JMeter installation

File ID different from the URL File ID - Google Drive API

I'm trying to access a file in a Google Drive directory but linking to it using the File Id provided by the API it says that i don't have permission. What i saw is that the File Id in the URL is different from the one who returns from the API. Why?
Using the test page of the Google Api it returns a "Not Found" error(404) and not the "No Permissions" error. Anybody knows how to get this ID(same of the url) that links to the file instead of the File's ID
Edit: Found that the File Resource has a property called "webViewLink" is it the link to the file instead of using the ID?
When you are trying the Drive API, you can set using fields property what values you want to return from your call as it is shown in this image:
webViewLink will return you the link that's shown when you open the file in your browser.
id will return you the ID of the file.
I specified some values, but you can see HERE all the values you could use and if you put "*" you will return all of them. Also, I didn't show in the image the id of the file to not share that info.
HERE you can see why you are getting that error. Surely, you don't have enough permitions because you have already checked that it exists for what I understood in your question.

MSword file attachment not working in codeigniter

I am using codeigniter and I am trying to send an email with an attachment, It is working well when i upload pdf but if i upload word file, i receive an empty email, although I have checked the uploading of word file is successful as well, all the uploaded files are in the given path. But there is nothing in email in MSword file case. Here is my code:
//My email function in controller
$attachment = $_FILES['file']['name'];
$this->email->attach('uploads/enquiry/'.$attachment);
You need to provide full path of the file.
so instead of
$this->email->attach('uploads/enquiry/'.$attachment);
try something like this
$this->email->attach(FCPATH.'/uploads/enquiry/'.$attachment);
Try it this way,
You will surely get answer :-
http://ellislab.com/codeigniter%20/user-guide/libraries/file_uploading.html

Replacing the body of a proxied subrequest with the contents of a file

I'm using the upload module to write the uploaded file to disk as soon as it arrives in nginx. In addition, I'd like to create 2 subrequests:
POST to a URL containing the uploaded file
POST to another URL without the uploaded file
The second request is easy to do because the upload module has already stripped out the upload. My problem is with the first request: How do I get the uploaded file back into the the subrequest.
A solution for my question has been committed to the echo module.
The module you linked to has the upload_set_form_field directive and a few special variables (listed in that directive), which you can use to pass the file details to the backend as a POST variables. The example given appears to put the upload back in the POST data. Can you adapt your backend script to make that work?

Downloading CSV via AJAX

Can you use AJAX to download a generated csv file from a web application? If so does anyone have any kind of reference that I could be pointed towards?
EDIT: Sorry I should have mentioned I am using Prototype's Ajax.Request and I looked in firebug's response tool and the generated CSV is the response, I just need to get it to pop up with the save file option after has been generated by the Ajax.Request
This is a known limitation of Ajax requests, you will need to use JS like:
window.location='download-csv.rb';
Instead of using an Ajax request. Another way is to change the location of a hidden Iframe, but this has it's own pro's/con's.
You will never get an Ajax request to display the 'file save' dialog, no matter what HTTP headers you send.
In light of your latest edit, to make your CSV file trigger a file download (instead of rendering in the browser), there's no need for Ajax.
Instead, the solution is to have your back-end system add this HTTP header when the CSV file is requested:
Content-disposition: attachment; filename=<your_filename.csv>;
Your implementation here depends on the back-end system you're using. If you're using Rails (as your username suggests), here's a start:
filename = 'your_filename.csv'
headers['Content-Type'] = 'text/plain'
headers['Content-Disposition'] = "attachment; filename=\"#{filename}\""
render :layout => false
Downloading it isn't the problem; you can download any data you like via XmlHttpRequest. The hard part is parsing it. There are several ways to parse it, from regexs to string indexing.
You can use "AJAX" to download anything .. Some people would say you shouldn't call it AJAX in that case since that term is rigorously devoted to downloading XML. But really it's just a mechanism to get data into the client w/o reloading a page. If you were loading HTML it'd be called AHAH, for CSV i guess you'd call it AHAC or AJAC? ..

Resources