Is there a function in the Chrome API that gets the most recently downloaded file?
My goal is to grab this file, copy it, and save it to a different location since in Chrome you cannot change the default download directory for specific file types/websites:
How to set download location via chrome api
Is this idea feasible?
The chrome.downloads API just became stable with Chrome 31. It allows you to deal with all download interactions, like getting the filename and the MIME type. I'm not sure if and how you can copy and move files on the user's system by a Chrome extension.
For your goal you could use the onDeterminingFilename function and alter the filename to contain subdirectories, like putting all .jpg files into Downloads/images/.
Related
I use tampermonkey on mobile firefox. In userscript I use GM_download(url, name) to download file from url. When it start download same file in firefox the result of this is :
Hello.txt
Hello(1).txt
...
Hello(9).txt
I want to know how not download duplicates. Or way to block firefox download duplicate.
Or get directory list. If there file alredy exist dont download.
In bash(linux cml) you write ls ,in windows you write dir. But how it would be in userscript? If yo write file:///storage/emulated/0/Download/Hello.txt in your browser it show all files that you want (in this address is Hello.txt file). But I can't get this html or whatever is this via XMLHttpRequest
Ps: Sorry for my english
You cannot access the filesystem to check if some file exists. That would be pretty dangerous for userscripts - imagine you installed userscript that did that. Firefox doesn't even allow plugins to access filesystem AFAIK, so tampermonkey cannot provide that API.
What you can do is to remember the name of the downloaded file. Your options are:
localStorage - for example set localStorage[filename]=true and then check for that. But if you delete the file on your phone, this will prevent you from downloading it again
indexedDB this is nicer for saving data, but the problem is same as for local storage.
You can store the list of files downloaded with your user script, but cannot access the directory list I think.
In IE, it's quite easy to "Open in Excel" a url to a file on a network or internet location. Is the same possible in Chrome though? The file must be opened from its current location, not from a downloaded copy. So when the user saves any changes, they save to the original location. IE Tab isn't an option either, we cant install chrome extensions.
Things I've tried:
1) Web protocol: "ms-excel:ofe|u"
Open in Excel
2) ActiveX (I know it wouldnt work with Chrome, adding for completeness)
<input type=button onClick="test()" value="javascript solution">
<script type="text/javascript">
function test() {
var Excel = new ActiveXObject("Excel.Application");
Excel.Visible = true;
Excel.Workbooks.Open("//server/folder/Test.xls");
}
</script>
3) Direct link to the file:
Click<br />
This just downloads the file to the local machine and can be set to open as soon as it downloads, but changes are saved locally.
UPDATE:
I've found that trying to access a file stored in sharepoint works using method 1 above.
Open in Excel
Any reason it would work for sharepoint files but not files stored in a network location?
UPDATE:
I've found documentation for the ms-excel:ofe|u| web protocol which states that only http and https are supported.
*Bounty will only be awarded to answers to the specific question:
Is there any way to open a file in excel with chrome where the path to
the file is a local or network storage location rather than a
http/https url?
No it is not possible for security reasons. All newer browsers (and I guess even the newer implementations of IE), don't allow file access to the local system. Internet Explorer is the only browser that supports opening files from locations, that are seen and treated as local ones.
You can open files from a Webdav Server, which is probably, why you can access files from your SharePoint, so you could try mapping that provider of your network drive as a Webdav Server.
Source: https://www.codeproject.com/Questions/1180249/Open-edit-save-excel-sheet-from-browser-using-java AND
Is there an Application URL Protocol for MS Word?
You upload your excel on Google drive and people can use it from google sheets.
Browser functionality is to download the copy of file to local Computer.
You should use File server FTP server and other Protocols to actually edit file at source.
There are Web file manager software which can give you ability to save file. Try Cloud version of software etc to save file in web page and see the version history too. GitHub can have Private repository too.
I have a Chrome Extension that needs to temporarily save a few (two or three) PNG images.
What I am currently doing is getting the image data URI, and saving this in localstorage. But I know that this is not a very good way of doing it, especially as some of the images are bigger than 5mb, and I therefore have difficulty storing them.
I've seen a few extensions (Single File Extension, and a few others) that have the ability of "saving" a temporary file in the extension folder, but I am not sure how I can achieve this.
Can anyone help me out?
You can use HTML5 FileSystem APIs to save your images to a target directory.
If your option is not limited to chrome extensions, you can write an chrome app, and then chrome.fileSystem is available to you.
I'm writing a chrome extension which will add custom images to a webpage. I want the users to put all their images in the "backgrounds" folder, and I want my extension to be able to retrieve the file names of every file in the "backgrounds" directory in the extensions folder. It seems like there is no way to do this in chrome extensions. When I try to use the chrome fileSystem API, I get this error:
There were warnings when trying to install this extension:
'fileSystem' is only allowed for packaged apps, but this is a extension.
How can I do this?
You can get read-only access to your extension's folder with chrome.runtime.getPackageDirectoryEntry, with which you can work using the HTML5 FileSystem API.
However, this will not allow you to do what you want to do.
While you're developing an extension, it will work fine, as Chrome does not mind changes to the extension's folder - they are expected.
However, when the extension is deployed to users, Chrome will maintain a cryptographic hash of the extension folder's contents. In case there are any external modification to the files, the extension is considered compromised and is forcibly disabled.
So you should consider other approaches instead, such as:
using the above HTML5 FileSystem API to have a virtual persistent filesystem to which you can let the user "upload" files through your UI;
storing data as blob:/data: URIs in chrome.storage or IndexedDB;
asking the user to put the files in a cloud drive your extension can access using its usual API.
For a website I am working on, I need to allow users to be able to specify the path to a file on a network drive, so I simply tried using a file field and having javascript get the value, however because of browser security I cannot get this path.
Is there anyway to get around this browser security and allow users to browse to the file on the network drive and select it to specify the path?
Thanks,
Alex.
AFAIK this is impossible with javascript. Flash also forbids from accessing the client file paths. ActiveX could be used but it will work only in IE and must be installed on the client computer.