I am using a rails app to display data that is stored in a sql server db. Data entry is all done through an MS Access front end into the sql server db. The rails app is "read only" viewer of information entered via the access app.
In the access front end, I use a bound object frame to let users upload documents of various types (.pdf, .msg, .docx etc.) into the database. The object is stored in a varbinary field on my sqlserver. This works fine when using the Access front end. Docs are properly retrieved and displayed with the right host app.
The problem is when sending those same objects back to be viewed through the rails app.
When I try to send the binary data down through the browser the file as a file, the file received is unreadable by its host app. The file extension is correct for the file sent down, but the applicaiton cant' seem to read them. I'm definitely getting something coming down -- when I examine the files in notepad I see snippets of the text, but something is wrong with the files so they are unreadable by MS Word or PDF Reader, etc.
The code in the controller is pretty simple:
def view_word_doc
a=Attachment.find(params[:id])
send_data a.Document, :filename => 'flibber.docx'
end
(Document is the field int he table that has the varbinary)
This has the expected result in the browser, I am asked if I want to open or save the file, and it attempts use word to open the doc. However word says the document is corrupted. Similar results when I try to open .pdf, .msg files etc.
I also tried using send_file. In that case I get a controller error --
Encoding::UndefinedConversionError in AttachmentsController#view
"\x81" to UTF-8 in conversion from Windows-1252 to UTF-8
I have left the type to default, which I understand is Application/Octet-stream but I'm not so familair with what this means.
As I mentioned, this all works fine with the access front end. Just can't send it properly in rails.
It is possible that you have coded to receive the files as a GET method in your routes.rb so it attempts to display them inline/in the browser or potentially a link used in the view whereas it needs to be a button which uses the POST method by default.
Related
I am trying to write some text to the file on Server. Text file server path is:
http://test.info.com/log.txt
So, whatever we will write on this text file can able to see in browser. Please anyone suggest me.
In one word, There is no on the fly write possible from mobile to server file.
Justification:
Question:
What's happen if I paste the logfile URL(http://test.info.com/log.txt)
into the browser?
Answer:
It will just download the log.txt file. Also, It will not allow doing
direct editing in the browser too. If it will is not feasible from the browser So how can we do it from the mobile end?
Alternatives:
Recently I worked with the same type of requirements. I have achieved it by creating the local log.txt file. Write into this file. Every day, I have uploaded the same log file into the server.
To write into the log file, I have used SwiftLog(Simple and easy logging in Swift)
You need to create 2 APIs on the server where your text file is kept. One API to get the data of the text file. Once that is done, show it in a TextView and edit it.
After editing, you can call another api to send the updated data back to the server.
My goal is essentially to upload a video file, like this, but with Ruby on Rails instead of PHP. I can successfully send JSON data to my server, but haven't been able to get file uploads working. The end objective is to have the file be in the server's /tmp directory, just like files uploaded via a webpage file_field_tag.
This image:
shows what I've tried so far. The result is that on the server, the parameter list is empty, unlike if you had used a file_field_tag. In the PHP example, they are able to get the contents of the file from the input stream... maybe there is something similar in Rails?
I know my API works, as I was able to successfully make a request using a JavaScript XMLHttpRequest, so I'm led to believe the solution involves working around what App Inventor offers for HTTP requests.
Edit: Removed unsupported header since the PHP example doesn't use headers anyways
I'm currently working on a intranet webapp for a company.
I've created it so the administrators of the site are able to upload files
(.docx, .pdf, .xlsx, .ppt etc) up to the webapp, to provide easier access
to documents for the employees. It works very well, however my client wasn't
too fond of having to download the files, and wanted it to pop up in the browser,
or open up the file-spesific program instead of download.
I was playing with some ideas:
1. Somehow parse the files to JSON at upload, and then show the content in browser with html.
2. Generate a pdf from the uploaded file (which automatically launches in the browser).
3. Somehow use a previewer to show the filecontent in the browser
4. Clients computer launches the uploaded file automatically on download, however I think this is a bit more tricky...
What would be the best and most time-efficient way to go about this?
It feels like what you actually want/need is a javascript document viewer (only) such as http://viewerjs.org/.
I have an advertising site running where users can post "headlines" and "sublines" in a form. I want to take this thing further.
Users should upload their .txt or .rtf file, comma seperated, so that it's created in my database.
Let's say this is the users rtf or whatever:
This is my headline; This is my subline;
This is my second headline; This is my second subline;
How can I achieve that this is parsed and written to my database? No csv or whatever. Just a simple text file.
Where should I put this form?
How can I parse it?
You might want to look at using Paperclip to upload the file & then you'll be able to access its data using this answer: How do you access the raw content of a file uploaded with Paperclip / Ruby on Rails?
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.