Display ".doc" ".docx" in browser - ruby-on-rails-4

My users can upload their CV and this CV should be seen by any employer.
My problem is that my client want this CV to appear in the web browser without any download.
PDF work fine but doc & docx don't.
I've tried to use both gem ("docx" and "doc_ripper") but each one can just handle basic thing (table won't work ...)
The cv is attached to one user and stored on Amazon with Dragonfly
I've try the google view : http://googlesystem.blogspot.be/2009/09/embeddable-google-document-viewer.html
But as I do : user.cv_file.remote_url(expires: 5.minutes.from_now)
The url doesn't work anymore (this solution only work if the document is public)
I thought to make a second field which have the cv_file convert as a pdf if it's not.
Any possibilities to give a public permission to aws file for 2-3 min (time to render it with google view tool)
Thanks.

I assume you are talking about a file stored on S3. To make a file on S3 temporarily public you can generate a pre-signed URL with an expiration date/time: http://docs.aws.amazon.com/AmazonS3/latest/dev/ShareObjectPreSignedURL.html

I've used the gem htmltoword a few times now and it's done a good job from that end of the translations.
I did a quick search and there are a few promising gems that might help you out here - converting the resumes from Word (.doc, .docx) into an format that you can get to HTML for your views (perhaps storing this converted content in a DB table/column?).
Word docx_converter
Google Groups discussion of the issue
ydocx
docx

Thanks for answering but after many research, I finally found :
https://view.officeapps.live.com/op/view.aspx?src=
which work as well as the pdf reader from browser.
Be sure to have a public url for the file you want to display

Related

Correct way to fetch data from an aws server into a flutter app?

I have a general understanding question. I am building a flutter app that relies on a content library containing text files, latex equations, images, pdfs, videos etc.
The content lies on an aws amplify backend. Depending on the navigation of the user in the app, the corresponding data is fetched and displayed.
I am not sure about the correct way of fetching the data. The current method (which works) is that the data is stored in an S3 bucket. When data is requested, the data is downloaded to a temporary directory and then opened and processed in the app. This is actually not slow, but I feel that it is not the way it should be done.
When data is downloaded a file transfer notification pops up, which bothers me because it is shown all the time. Also I would like to read the data directly with something like a get request, without downloading the file first (specially for text files, which I would like to read directly into a String). But here I don't know how it works, because I don't see that you can save data in a file system with the other amplify services like data store or the rest api. Also, the S3 bucket is an intuitive way of storing data that is easy to use for the content creators of my company, for me it seems that the S3 bucket is the way to go. However with S3 I have only figured out the download method to fetch data.
Could someone give me a hint on what is the correct approach for this use case? Thank you very much!

Remove the .html extension by using lamda edge - aws S3

Is it possible to remove the .html extension from using lambda edge. it would be a lot easier to write
const redirects = {
'/about': '/about',
'/contact.html': '/contact',
'/start.html': '/start',
I been racking my brain about this for so long. None of this works. My brain is dead now. So I am asking for help
The site is stored on S3 and is using cloudfront.
https://github.com/aws-samples/aws-lambda-edge-workshops/tree/master/Workshop1/Lab4_PrettyUrls
There's not any built-in feature that allows this operation, but there's a method you can try to accomplish your target.
Don't name the file as index.html, just name it as index. Web browsers never care about the file extension you have, especially if the content of the file is correct. As long as the content type is set to text or html when the object is uploaded to S3, this works perfectly. And if you are using the console, you will have to set that manually because its not assumed automatically.

.csv upload not working in Amazon Web Services Machine Learning - AWS

I have uploaded a simple 10 row csv file (S3) into AWS ML website. It keeps giving me the error,
"We cannot find any valid records for this datasource."
There are records there and Y variable is continuous (not binary). I am pretty much stuck at this point because there is only 1 button to move forward to build Machine Learning. Does any one know what should I do to fix it? Thanks!
The only way I have been able to upload .csv files to S3 created on my own is by downloading an existing .csv file from my S3 server, modifying the data, uploading it then changing the name in the S3 console.
Could you post the first few lines of contents of the .csv file? I am able to upload my own .csv file along with a schema that I have created and it is working. However, I did have issues in that Amazon ML was unable to create the schema for me.
Also, did you try to save the data in something like Sublime, Notepad++, etc. in order to get a different format? On my mac with Microsoft Excel, the CSV did not work, but when I tried LibreOffice on my Windows, the same file worked perfectly.

Is it possible to purge an entire directory with the Akamai CCU REST API using a wildcard?

I think the title says it all. We have a site that uses a URL parts to specify locale, category, product, and product variation. For example:
/[country-code]/[category-slug]/[product-slug]/[variation-id]
As we support about 10 different locales, and some products have up to 30 variations, if we change a category, we can sometimes be trying to purge up to 1500 urls.
Is it possible using the Akamai CCU REST API to add a wildcard value, say for the country code, or variation id?
/*/[category-slug]/[product-slug]/*
I have seen some mentions of wildcards around but I'm not sure if they're supported by the API
This should be possible. When you go to CCU, click on "Refresh by Directory & File Extension". Hope this helps.
You can do a purge by CPCode.
I've just written a getting started guide for the CCU API:
https://community.akamai.com/community/developer/blog/2015/08/19/getting-started-with-the-v2-open-ccu-api?sr=stream
The only difference for your case is that you'll want to allow purge by CPCode, and set up a CPCode for the file areas you want to purge at once.

How to mix Django, Uploadify, and S3Boto Storage Backend?

Background
I'm doing fairly big file uploads on Django. File size is generally 10MB-100MB.
I'm on Heroku and I've been hitting the request timeout of 30 seconds.
The Beginning
In order to get around the limit, Heroku's recommendation is to upload from the browser DIRECTLY to S3.
Amazon documents this by showing you how to write an HTML form to perform the upload.
Since I'm on Django, rather than write the HTML by hand, I'm using django-uploadify-s3 (example). This provides me with an SWF object, wrapped in JS, that performs the actual upload.
This part is working fine! Hooray!
The Problem
The problem is in tying that data back to my Django model in a sane way.
Right now the data comes back as a simple URL string, pointing to the file's location.
However, I was previously using S3 Boto from django-storages to manage all of my files as FileFields, backed by the delightful S3BotoStorageFile.
To reiterate, S3 Boto is working great in isolation, Uploadify is working great in isolation, the problem is in putting the two together.
My understanding is that the only way to populate the FileField is by providing both the filename AND the file content. When you're uploading files from the browser to Django, this is no problem, as Django has the file content in a buffer and can do whatever it likes with it. However, when doing direct-to-S3 uploads like me, Django only receives the file name and URL, not the binary data, so I can't properly populate the FieldFile.
Cry For Help
Anyone know a graceful way to use S3Boto's FileField in conjunction with direct-to-S3 uploading?
Else, what's the best way to manage an S3 file just based on its URL? Including setting expiration, key id, etc.
Many thanks!
Use a URLField.
I had a similar issue where i want to store file to s3 either directly using FileField or i have an option for the user to input the url directly. So to circumvent that, i used 2 fields in my model, one for FileField and one for URLField. And in the template i could use 'or' to see which one exists and to use that like {{ instance.filefield or instance.url }}.
This is untested, but you should be able to use:
from django.core.files.storage import default_storage
f = default_storage.open('name_you_expect_in_s3', 'r')
#f is an instance of S3BotoStorageFile, and can be assigned to a field
obj, created = YourObject.objects.get_or_create(**stuff_you_know)
obj.s3file_field = f
obj.save()
I think this should set up the local pointer to s3 and save it, without over writing the content.
ETA: You should do this only after the upload completes on S3 and you know the key in s3.
Checkout django-filetransfers. Looks like it plays nice with django-storages.
I've never used django, so ymmv :) but why not just write a single byte to populate the content? That way, you can still use FieldFile.
I'm thinking that writing actual SQL may be the easiest solution here. Alternatively you could subclass S3BotoStorage, override the _save method and allow for an optional kwarg of filepath which sidesteps all the other saving stuff and just returns the cleaned_name.