How do I access local PDF files in my Chrome Extension app? - javascript

Google Chrome allows you to preview local PDF files in the browser like pictured below:
I am working on an extension that takes whatever PDF is in the browser preview and opens it in my custom editor/markup tool.
I have been successful in loading PDFs from remote URLs because I can just send the remote URL to my server, download it there, and open the PDF in my app using PDFjs.
How can I accomplish the same functionality for local PDF files?
I have looked into possibly using javascript to create a File object from local PDF files but Chrome doesn't allow access to the local file system.
I am hoping to accomplish this functionality by the user just clicking my extension icon, similar to the popular extension, Kami.

you need to add permissions to your extension:
"permissions": ["file://*/*"]
to ensure that you have permissions for local files, use:
chrome.extension.isAllowedFileSchemeAccess
P.S. have a good day and do not use upwork for these type of questions :-D

Related

Open Files in Browser instead of downloading (including files like .doc, .xls etc)

I am using Java Rest APIs to upload files in my project. Based on the configuration my files either goes into s3 bucket, google drive, one drive or even in local file system (in the same machine where my application is running). During download again I am making an ajax call which returns the file in response with Content Disposition header attachment; and browser downloads the file irrespective of its format. I want an option to view these files in the browser instead of downloading it directly. How can I do that ? (Especially formats like doc,xls etc)
As far as I know, there are no client-side libraries exist that can open .doc, .docs, .xls in browser. There is a way to render render your files using browser is to use Google Documents' Viewer or Microsoft Office 365 viewer via an <iframe>. Using this inside an <iframe> you can open your file in side your browser but can not edit.
Google Documents' Viewer inside <iframe>
<iframe src="http://docs.google.com/gview?url=http://example.com/path/to/your/document.doc&embedded=true"></iframe>
Google Documents' Viewer clickable link <a>
Open your doc file
Microsoft Office 365 viewer <iframe>
<iframe src='https://view.officeapps.live.com/op/embed.aspx?src=http://example.com/path/to/your/document.doc' width='1366px' height='623px' frameborder='0'></iframe>
Browsers don't have any built-in way to view Word docs so unless the user has configured their browser to open it with some plugin (which 99% of the world hasn't done), the browser will prompt them to download the file.
However, if you only need to display the Word Document, but don't need to edit it, you can use Google Documents' Viewer via an to display a remotely hosted .doc/.docx.
<iframe src="http://docs.google.com/gview?url=http://url-of-the-file&embedded=true"></iframe>
you can generate temporary URL for your s3 documents by keeping them private.
if you are interested in giving users privilege to edit them online then you can go with any tool like onlyoffice

Programatically save files to user specified location in firefox extension

I'm writing a firefox extension that writes files to a directory structure at a specified location by the user but can't seem to find documentation on how to include that in the permissions of the extension or how to access this facet in the API. I was initially trying to use a greasemonkey script to accomplish this but ran into the javascript limitation of not being able to access the user's local storage and had read I needed to write it as an extension. Any link or help on how to write a function for a mozilla extension that will save a file to a local disk location? Thanks in advance for any help!

Google Drive API should open a local URL

i´m searching for a way, that a google drive app opens a local url from my extension.
I only know the way, that my extension redirects after opening a file with my extension to an web URL.
I need a way, to open an javascript (e.g. index.js) from the folder of my extension, that is installad on the users pc.
Does somebody knows a solution?
The background of this workaround: No private data should go to my webserver. All actions should be handled over javascript in the browser of the user.

Share files with Google Drive SDK

I've been following Google's documentation to share files on Drive: Share Files
If I upload a file to Google Drive from the Google Drive interface, then try to share this file from my webapp, i get the following error in my javascript console:
in chrome:
Refused to display 'https://drive.google.com/share?id=0B6UmN_AivG7SLWVYakF2Rk1CdDg&foreignServi…=postMessage&appId=958414147877&embedOrigin=http%3A%2F%2Fsandbox.velop.org' in a frame because it set 'X-Frame-Options' to 'SAMEORIGIN'.
in firefox:
[14:04:41.157] Load denied by X-Frame-Options: https://drive.google.com/share?id=0B6UmN_AivG7SLWVYakF2Rk1CdDg&foreignService=explorer&shareService=explorer&shareProtocolVersion=2&command=init&subapp=10&popupWindowsEnabled=true&shareUiType=default&rand=1370585078609&theme=2&client=postMessage&appId=958414147877&embedOrigin=http%3A%2F%2Fsandbox.velop.org does not permit cross-origin framing.
Now the weird thing is if I create the file from my webapp and upload to Drive through the api, I am able to share the file without problem.
Even stranger, it is enough that I open the file once from within Drive ( I have installed the webapp in my Drive so I can open files using my webapp) to be able to share it, even if later I don't use Drive to open the file anymore.
Any idea what could be causing this kind of behavior?
In my Drive SDK console, I set the Open URL to: http://sandbox.velop.org/my-google-drive/detail
When I open the file in Drive using my webapp, Drive thus redirects me to: http://sandbox.velop.org/my-google-drive/detail?state=%7B%22ids%22:%5B%220B6UmN_AivG7SLWVYakF2Rk1CdDg%22%5D,%22action%22:%22open%22,%22userId%22:%22105908447865504163566%22%7D (able to share)
When I open a file in my webapp, the URL is like: http://sandbox.velop.org/my-google-drive/0B6UmN_AivG7SLWVYakF2Rk1CdDg/detail (able to share only if opened from drive once before)
EDIT:
I realized this is the standard behavior for Google Drive API as described here:
When users approve these scopes, the app is installed for the user, with access to files that the user creates or opens with the app.
Is there a way to allow the app to open / write any file?
I thought that using the https://www.googleapis.com/auth/drive scope when registering my app would allow me to do this, but doesn't seem to be the case..
I am running into exactly the same issue.
My app is requesting the full drive scope (so the app should have access to all files).
But sharing only works if the file has been opened by the user from the drive before.
There seems to be some magic "while-listing" of files that have been opened from drive.
When accessing a file that has not been opened from drive before I get...
Refused to display htps://drive.google.com/share?id=0534534543iTEhYamxfUnc2MnM&foreignServi…ent=postMessage&appId=46459361793&embedOrigin=http%3A%2F%2Fwww.editey.com' in a frame because it set 'X-Frame-Options' to 'SAMEORIGIN'.
...which obviously is misleading as the share button is not in a frame.
Opening the give url in a new browser tab gives a hint to the real root-cause:
Application '3453459361793' is not authorized to access document "0B0o5345345DAc_SiTEhYamxfUnc2MnM".
My app should have access to the document but it looks as if the "share dialog" acts as a separate app that will only allow access to files that have previsouly been opened from drive.
For security reasons drive will not let you use that dialog unless you're at the URL specified in by your "Open URL".
Your current URL http://sandbox.velop.org/my-google-drive/0B6UmN_AivG7SLWVYakF2Rk1CdDg/detail != http://sandbox.velop.org/my-google-drive/detail
So you might want to change your URL structure. Maybe something like http://sandbox.velop.org/my-google-drive/detail?open=B6UmN_AivG7SLWVYakF2Rk1CdDg
This is real pain in the neck, especially when developing on a different domain.

Chrome Extension Save File Dialog

Please I am new to building Chrome Extensions. After the user installs the extension, I want them to configure it by specifying a directory where the app can save files. I want to do this by opening a save file dialog so they can browse to the folder of their choice. How do I do this?
The answer is that there is no means in the Chrome Extension API to write files outside of the sandboxed file system provided by Chrome. This could theoretically be done by writing an interface in C and then call that, but so far I have not yet seen a successful implementation.

Categories

Resources