Saving the file on a user selected location using rails - ruby-on-rails

We are developing a functionality that allows the users to save the downloaded file. We are struggling to get a popup where the user can select a target location / folder to save his file. Can this be achieved using rails?

I think you're looking for send_file - it's very easy to use.

I think it depends on the content-type and similar headers you're returning to the user.
Try returning something like:
header('Content-disposition: attachment; filename=movie.mpg');
header('Content-type: video/mpeg');
EDIT: I am assuming you're able to generate headers and returning a file to the user by HTTP (no simple links to files)

I think you are trying to give something like file browser dialog box which allows client to save file on a particular location.
In case you are trying to give this from your server then I should say it is not possible due to security restriction which browser makers have applied to ensure client's security.
Another way is to let client download your browser plugin/activeX Control which basically is control over client's machine then you can do what you want i.e. something like this also.
I think without this the filetype downloaded by client is identified (based on headers) by browser and it opens the file save dialog box automatically and you cant enter into client's secure arena.

I think you want download file option. For example on hitting a URL you
want user to download a zip file code for it you can do something like
this:
class MyController < ApplicationController
def downloadzip
send_file "path_to_file", :type=>"application/zip"
end
end

Related

Brackets Shell URI

Does anyone know if Brackets Shell uses any URI except the file://...index.html format? I want to point a web service back to the shell and need to provide a valid URI with the URL. The problem is that I noticed that the URL for the index file uses basic system paths and this can change per system or user configuration.
Any way around this little problem?
Edit:
I am trying to access the Instagram API through brackets shell. In order to gain an access token to the OAuth method they use I need to redirect the user to the Instagram Login page to log in then grant access and then Instagram will redirect them back to me based on the call back or redirect url provided from me. If it was as simple as providing just the URL when the call was made I would be fine however to get a client key (which is also needed to access the api) I need to provide the correct call back URL once the key is made and since the shell seems to have no custom file path it's almost impossible to predict the file path based on each users setup on their own pc's. I hope this made sense :)
I searched the source of the brackets-shell, but couldn’t find the startup path. A quick workaround would be adding a meta-refresh to your index.html which redirects to the corresponding URL of your web service.
For example:
<meta http-equiv="refresh" content="0; url=http://example.com">
If you don’t want to select your index.html each time you start your custom shell, you should place your index.html at
Mac: Brackets.app/Contents/dev/src/index.html or Brackets.app/Contents/www/index.html
Win: dev/src/index.html or www/index.html (these folders must be in the same folder as Brackets.exe)
Linux: dev/src/index.html or www/index.html (these folders must be in the same folder as the Brackets executable)
You can get the current location through javascript using
document.location.href
this will return a string like
"file:///C:/Program%20Files%20(x86)/YourApp/www/index.html"
which you might try sending to Instagram. I'm not sure if they will accept file URI's though.

ActionScript FileReference upload onComplete

I am a complete beginner in Flash & Actionscript.
My pet project is this: To provide a www.imageshack.com like service where people could upload single images and later anyone can view it using the generated url.
So far I have gotten to upload an image using Flash and store it in a directory.
http://pixels.guygar.com/
You can check the uploaded image at:
http://pixels.guygar.com/warehouse/
The issue being, I was under the impression when the PHP file is called to store the image in the folder /warehouse the browser would automatically navigate to:
http://pixels.guygar.com/upload.php
Where I can process the image i.e. generate a unique file name and provide the user with a unique URL to later access the resource.
What is happening is the image gets uploaded by the PHP script but the browser page still stays the same page even when providing a new url in the PHP script.
So the question is how do I go about so that a new URL (image resource linked) is passed back to the flash so that onComplete is called I can navigate to image that was just loaded? Or other ways of doing such?
I welcome your perspectives on this issue and thank you for your guidance.
i would store all values that you need later on in a session on the server (don't forget to pass the sessionID to the upload-script via GET).
at the end of the PHP script you just return "ok" (or "ko" if sth went wrong) to flash and then (in the callback/listener) call/load a second PHP-script that's doing the rest ... and returns you an URL to a thumbnail or whatever you want to do.
hope this points you in the right direction ...
http://help.adobe.com/en_US/FlashPlatform/reference/actionscript/3/flash/net/FileReference.html?filter_flash=cs5&filter_flashplayer=10.2&filter_air=2.6#event:uploadCompleteData
Shows how data can be returned to flash after an upload.

How To Dynamically Route to Downloads

Basically, this is what my app does:
It sends an AJAX request
The server creates a file
The server sends back the URL of the
file location
The client-side will attempt to
create a dialog to download the file
at that location (probably using a
frame? I haven't got this far yet).
My question is, how do I dynamically route to the files I create so that they are accessible when you browse to them? If I don't add a route for them, then they will get a 404 if they try and access the directory they're in.
The files are currently stored in a folder in public.
Would the best way to deal with this make the folder somehow not require a route, so that it can be browsed to directly, and then have an index page on it so they can't view the full list of files? If so, please let me know how I can accomplish this. And on a side note, if you have an idea of how I can accomplish JS displaying the download dialog let me know.
It's Rails 3 by the way.
Thanks!
For a full private set of files: choose a place for your files outside your public directory, then configure X-SendFile support in your web server and finally use send_file in your rails application.

ASP.NET MVC Response file should not download

I am generating a .cxml file on the server and pushing it to the browser based on certain queries. If I just link to a .cxml, it does what I expected and opens it in the respective application.
How can I generate a file and push it to the browser just like if it was linked to a file without it asking me to download it?
The link looks something like:
http://localhost/MyController/GetFile?q=TheQueryStringParam
Thanks.
Simply Response.Write(yourFileText) should do the trick

How to send a file to the browser using ASP.NET MVC controller action?

I have an application where I allow my users to upload a file of any type. I save this in the file system on the server. The application will only be accessed by two users, so I don't need to worry about uploading any dodgy files.
How do I allow my user to press a button on an MVC form to request the file be sent back via the browser and be presented with the standard save/open dialog?
I want to return any type of file, and the example I've found always specify the type of file being returned. Is there a simple example of this?
See FileResult and derived classes.
An alternative approach is to set HttpContext.Response.ContentType to the proper mimetype and then writing the contents of the file with HttpContext.Response.OutputStream.Write ().
Useful if, for example, the data is not in a local file but stored in a database as a binary blob.

Resources