RoR: Get file (attachment) name/location - ruby-on-rails

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.

Related

restrict .bmp, .exe, .bat attachment types while uploading for an issue in JIRA

Is there anyway to restrict the attachments of types - .bat/.exe/.bmp, etc to be restricted while user trying to upload them in JIRA.
I tried using the Servlet-Filter plugin module in JIRA. But I am not able to get the URL at the time of uploading the attachment. Also I am trying to listen to the Attachment event for an issue.
Is there any other alternative of restricting these file types.
Any help will be much appreciated.
Thanks!
Well there was an Attachment Filter available but I am not sure if it is still relevant - it actually seems that it is no longer relevant also if I recall correctly it was for
Confluence. So you're left with writing a custom plugin for this.
You could implement com.atlassian.jira.issue.AttachmentManager, the default implementation is com.atlassian.jira.issue.managers.DefaultAttachmentManager and wrap it so that you check what's going on with the upload - filetype etc. But be sure to check the mime-type - not only the file name and/or extension. Check this out.

How to show only the link of an uploaded file, not its location

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.

how to store the results of input (webkitdirectory) for later usage?

I'd like to allow user to select a directory (in which I parse some text files) and store the result(List<File>) in a PERSISTENT storage on the same client so that when the user returns, there is no need to select the same directory again.
During the session selecting the directory (via <input webkitdirectory="..." />) and then accessing the directory and parsing the file already works fine, but I've no idea on what kind of data I shall save in order to retrieve it later. I've tried by using window.webkitResolveLocalFileSystemURL() but wasn't successful so far... any idea?
Ok, so you're using something like:
<input type="file" id="file-input" webkitdirectory="" directory="">
This lets the user upload a directory. Roughly speaking, here's the code to get the list of files uploaded:
query("#file-input").on.change.add((e) {
print(e.target.files);
});
It sounds like you already figured that part out.
Really, you just get a list of files. I looked at e.target, and I don't think there's anything in there related to the directory itself. For instance, I don't see anything about the directory name, and it's not as if you suddenly have write access to that directory. You also can't upload files from that directory the next time the user loads the page without him selecting the directory again.
However, what you can do is upload files from that directory and save a copy of those files locally using local file storage.
See also:
"Using the HTML5 Filesystem API" p. 20-21
https://github.com/dart-lang/dart-html5-samples/tree/master/web/file
How do I use Google Chrome 11's Upload Folder feature in my own code?
By the way, I know I wasn't able to achieve exactly what you wanted, but if you approve of my answer, please accept it. My boss promised to buy me a puppy if I answer 100 questions on Stack Overflow ;)

Hiding the Inbox from the documents directory for File Sharing

Is it possible to hide the Inbox from the list displayed of the directories?
For example, in this screenshot from a tutorial, the inbox folder features. In my app I would prefer it not to.
Other apps (eg. Molecules) seem to manage this, so I assume it is possible.
(In case anyone is wondering I am a novice developer)
I very much appreciate any help.
So it turns out that although the Inbox directory is not writeable, it is deletable. Files opened through other apps will be automatically placed in this file, and if the inbox does not exist then it is created. So to get rid of it, simply delete it every time you handle an external file opening.
Very simple, just got thrown when I tried to edit a file in the inbox, which raised an exception, making me think the inbox was write-protected.

open an excel file located on the server instead of download it MVC

I'm building a Reporting web application right now with MVC3 and I've come up to a couple problems.
My goal is to have it able to generate and view Crystal Reports, SSRS reports, and Excel documents.
Right now I'm working on the Excel segment and I'm running into more trouble than I thought I would. First off, when I link directly to the file, it either opens inside the browser or it downloads it from the server and if the user makes changes it doesn't actually save it to the true file on the server.
I've tried both linking to the file directly using Razor and a ViewModel with the path to the document as well as directing it to an action that returned a File.
I've also tried linking it to a shortcut to the actual file thinking that if I could open the shortcut it would open the file the way I wanted it to and unfortunately it didn't really open at all.
The users already have access to the files on the server through a network drive, so as of right now they can go into the server, open the excel document, edit and save it no problem. I want to duplicate this effect through a link. The program already has a file browser built, so I can browse between the files and make links to the reports.
Thanks in advance!
Since they are apparently on a network drive, you can just link to the files directly, relative to the user?
For example: a link to file://///SERVERNAME/folder/
I tested it between two computers on the network, and that seems to work. However, you still get a popup asking that you want to do with the file, open or save. (both in firefox and IE)
Note: Yes, that many slashes seem necessary, lol

Resources