I have checked the Mimetype of the docx file and it shows: 'application/octet-stream'
But checking it without any content in it shows application/vnd.openxmlformats-officedocument.wordprocessingml.document as mimetype.
I don't know whether the problem is with the content inside the file also,
while uploading the file with paperclip it shows:
#content_type="application/vnd.openxmlformats-officedocument.wordprocessingml.document", #headers="Content-Disposition: form-data;
But when we check the file content after the upload it shows as "application/zip".
Tried all the mimetypes, but it doesn't seams to work.
Meanwhile other docx files are uploaded and downloaded in fine way, this particular file alone been downloaded as zip file while downloading it form s3 bucket.
I cannot provide the file because it is confidential so please leave suggestions if you have any solution for this ?
Note: the same file when it is uploaded in google drive and downloaded or also downloaded in safari it is downloaded fine the problem occurs when downloading it in chrome browser.
Try adding this to your config/initializers/mime_types.rb
[['application/vnd.openxmlformats-officedocument.presentationml.presentation', [[0..2000, 'ppt/']]],
['application/vnd.openxmlformats-officedocument.spreadsheetml.sheet', [[0..2000, 'xl/']]],
['application/vnd.openxmlformats-officedocument.wordprocessingml.document', [[0..2000, 'word/']]]].each do |magic|
MimeMagic.add(magic[0], magic: magic[1])
end
Don't forget to restart the server after :)
Related
I am using Ruby2.6.0, Rails5.2.3 and Kibana6.6.1.
I need some help to realise pdf download automatically. Is there any way to download pdf/png automatically using the following url in controller? 'automatically' means users won't feel the file download and don't need to click download icon.
http://localhost:5601/api/reporting/jobs/download/jvhs9dga06559d006260ms70
Edit:
Add the code I tried. It helps me to download a file. But I cannot open it with Chrome or sublime. It seems like the file is related to kibana Chromium sandbox (https://www.elastic.co/guide/en/kibana/current/reporting-chromium-sandbox.html). Is anybody know what type of this download file is and how to open it? How to save it as pdf/png file in my local folder?
File.open('./public/testfile.png', "wb") do |file|
file.write open("http://localhost:5601/api/reporting/jobs/download/jvhs9dga06559d006260ms70")
end
I am using shrine for excel file uploading. File is successfully uploaded and linked to model instances using shrine.
I wanted to open that Excel file(.xls, .xlsx) in browser instead of downloading it. I have looked for various solutions and tried them, but no luck.
The recommended solution from most of the people is using 'send_data', I have tried with that also:
send_file(data, type: 'application/vnd.ms-excel', filename: "#{uploaded_file.metadata["filename"]}", disposition: 'inline')
But it is downloading the file instead of opening it directly in browser.
My questions are
1) Is this opening/downloading file depends on browser settings?
2) Which one is better? To open a file in browser OR use gem like 'axlsx' to create and render excel templates in app?
Thanks!
Whether the browser will attempt to open the file in the browser or download it is determined by the Content-Disposition response header.
Content-Disposition: inline # browser will attempt to display it
Content-Disposition: attachment # browser will always download it
You can also specify the filename in both cases, should the user choose to download it:
Content-Disposition: inline; filename="table.xls"
Content-Disposition: attachment; filename="table.xls"
How to ensure that the Content-Disposition is specified to inline depends on where you're storing your files. If you're storing them on the filesystem, I think that the Rails::Static middleware already has the "inline" behaviour. If not, you can switch to download_endpoint.
If you're storing them on Amazon S3, you can specify the default :content_disposition upload option on Shrine::Storage::S3 initialization:
Shrine::Storage::S3.new(upload_options: {content_disposition: "inline"}, **options)
I am having a lot of trouble syncing file revisions to dropbox with the "withParentRev" parameter in "uploadFile."
Basically, I export information to a .pdf file. I want to upload the .pdf to dropbox, and if it's a new file it should upload it with "withParentRev=nil," but if the file exists then it should get the revisions. I have tried using loadMetadata on the file, but because the dropbox calls are synchronous I am having trouble uploading the right files.
No one else seems to have good sample code on how to do and any help would be greatly appreciated!
I'm using swfupload to upload some excel files to my server. When the uploaded file is in the old (< 2003) format, everything works fine. I can upload the file, redownload it, and and confirm it is the same.
The problem is, whenever I upload a file in the new open xml format (> 2007). When I redownload that file and open it, I get an error:
Excel found unreadable content in 'filename'. Do you want to recover the contents of this workbook? If you trust the source of this workbook, click Yes.
I checked on the server and confirmed the same error is present there as well.
Additional info:
The files are stored on the server file system (not DB BLOBs)
If I "recover" the file, the contents appear to be exactly the same as the originals
This same system works fine for Excel < 2003 files and image files
I save the file on the server with File.WriteAllBytes(filePath, data) where data is generated by upload.InputStream.Read(data, 0, upload.ContentLength)
I need to extract Thumbnails from files in a Folder.
I tried with this example but it doesn´t always work.
It gives me thumbnails of images and PDF files, but not of Word, Excel, Text, OpenOffice, etc. files.
Edit: What I mean with "It doesn't work" is "It doesn't return the image I expect. It returns the icon of the application used to open the file.
Edit 2: Windows Explorer does show me thumbnails of the files I mention "not working" (.xls, .doc, , .ppt, .odt, .ods)
I think you are mistaken. Not all .doc and .xls files are saved with thumbnails. Certainly .txt files are not saved with thumbnails.
I downloaded the demo code and tried it out. It successfully shows thumbnails for .doc and .xls that showed thumbnails in Explorer. It shows standard icons for those files that do not have thumbnails when viewed in Explorer.
Here is a tool witch reads Thumbs.db file extracting images from it i hope it helps (source provided )
https://sites.google.com/site/delphibasics/home/delphibasicsprojectreleases/thumbsdbviewer
I don't know why the code you posted doesn't work properly it should...