How to show only the link of an uploaded file, not its location - ruby-on-rails

I have used paperclip to allow me to upload files to a rails application. Everything works and the file is uploaded, but instead of seeing a link to the actual file itself I see the location of it within the systems folder of the rails project.
I'm guessing its either a routing issue or I need to create a link to the file in question. However, I would like to hide the location of the file itself, and only see the link displayed.
I would be very grateful if someone could point me in the right direction here.

You want to hide the actual path of the file in the server, right?
You can achieve that using send_file (http://api.rubyonrails.org/classes/ActionController/DataStreaming.html#method-i-send_file) in a normal controller.
You will still need to do something to protect the download using the real path.

Related

Write files changes made when opening file through windows explorer in a mapped drive

I'm implementing a WebDAV file server using the ITHit WebDave engine, i have the following problem
When i list the files and open one of them i get the ReadAsync method called, i provide the content and the file is opened correctly
However any changes i make to the file can't be saved, i get an error saying
A device attached to the system is not working
I looked at the file system samples and implemented support based on the FileSystemStorage.AspNetCore sample,
From what can understand the WriteAsync method is used when creating new files, should i expect for WriteAsync to also be called for file edits that need to be changed?
Am i wrong in the assumption that DavFile.WriteAsync will be called with a stream for the updated content?
If WriteAsync is not the right location to save updates to a file, could you provide some guidance on the process of saving changes to existing files?
Edited to add:
Now i can see that after i dismiss the first error about the device not working i get the standard save dialog box, if i click save it asks me if i want to overwrite the existing file, after accepting to overwrite then WriteAsync is called and i can update the file contents
I'm not quite sure why it would first tell me there's an error and then still allow me to write the file but only as replacement to the original file
Thanks for your help
Fixed, i found that there were issues with the ILockAsync implementation, reviewing the FileSystemStorage sample helped fix the issue with locking files before writing or updating properties

How to show uploaded photo Ruby?

im new in ruby, here u can find my code: https://bitbucket.org/Messeir/reddit
I used carrierwave gem for uploading photos. Unfortunatelly i dont know how to show uploaded photo on main site near to submited links?
Here are a few thoughts.
The photo is uploaded. We're assuming that it'll land on the file system of your server somewhere.
After you receive the file upload, as a prototype, try to move the file in the Rails root "public/images" directory. On your page, you could try an image tag as such:
If that works, you can tell at least that your "file-upload-save-to-disk" operation is working.
In a second phase, save the file somewhere else, say in a /data/images directory. Create a controller that will respond to a /mycontroller/myimage?... url, an in that method, respond with the image content.
That's pretty rough but it's a start. Let me know how it goes.

Edit external links location in PDF and save the file

I just want to open a pdf file, replace the external links target than save the file.
The links text or image remains unchanged, just the location.
I've been looking at pdftk, combine_pdf but I couldn't figure it out how to do it or if it's even possible.
Can anyone point me to the right direction?
I prefer open-source solutions.
Thanks

RoR: Get file (attachment) name/location

In my app I want users to be able to associate a file(s) they have on their desktop/DropBox with a specific item, but I don't want/need them to be able to actually attach the file...I just want to get the file name and location and save that in my database. Then when I display the item I'll hyperlink to the location captured. Can someone point me to an example(s) of how to accomplish this? I looked at the JQuery File Upload (http://blueimp.github.com/jQuery-File-Upload/) but as I mentioned don't actually need to upload the file...so this should be something super easy.
Thanks for your time and assistance.
You can try and get value of file input, but you'll fail.
See this jsfiddle.
All I'm getting is the fake path
C:\fakepath\134.png
And there's certainly no C:\ drive on Mac OSX. :)
I guess, this is because of security restrictions. You shouldn't know (or care) about user's filesystem in a web app.

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.

Resources