Change external file name download attribute - html

I have coded a file download button and I want to change the file name when downloaded. The original file name is an ugly concatenation of Ids and is also signe by AWS.
When I use a local file, the downloaded is carried out as wished, with the modified name. But when I use the AWS stored and signed file I still get the real file name. Actually the issue occurs with all external files.
The example below shows the issue. The file should be download as newname.pdf. In my browser (Mac Chrome 67.0.3396.87) it's being downloaded as activities.pdf.
Test button

Probably not allowed by External servers: CORS headers.
Related: HTML5 download attribute not working when downloading from another server, even when Access-Control-Allow-Origin is set to all (*)

Related

Download dotfile using html5 download preserving name

I have a directory structure, containing a list of directories and files.
I want to give user an option of downloading a file. For downloading, I'm using HTML5 download attribute. It works perfectly.
But the directory structure i have can have dotfiles too, examples: .babelrc, .gitignore, .eslintrc, etc.
When I use the same technique to download such files, file is being downloaded with the same content but the file is no longer a dotfile. After downloading, let's say .gitignore, the file becomes gitignore.txt.
I'm using this for my project github-plus - Chrome extension to display size of each file, download link and an option of copying it's contents.
Any help would be highly appreciated.
I'm using this format:
Download
JSFIDDLE DEMO
Quoting HTML5 specification on downloading resources with the download attribute, about file type/extension :
If the claimed type is known, then alter filename to add an extension corresponding to claimed type.
Otherwise, if named type is known to be potentially dangerous (e.g. it will be treated by the platform conventions as a native executable, shell script, HTML application, or executable-macro-capable document) then optionally alter filename to add a known-safe extension (e.g. ".txt").
It seems that:
the part of the algorithm that finally choses the filename is platform-dependent
if the extension is not recognised, as in the case of dotfiles, the browser will try to determine it by using the file MIME type
dotfiles might be considered anyway as potentially harmful as they are hidden files on various platforms. This seems to be what happens in your case, with the initial dot being removed and the .txt extension appended.

Selenium ide to locate a file and store its path info from any computer

currently in my test scripts for automated file upload to browser, the paths are already defined in the value column
command type
target //input[#type='file']
value /Users/.../.../.../filename.extension
in such cases, this script is unable to run on other computers because the path would be different.
my question will be is
is there a way to locate the file in a general folder (for example file is downloaded and in the "download" folder), by using selenium ide can we get the path of the file (/Users/.../downloads/filename.extension)
store the path of the file with its extension into a notepad which i will be using it for multiple test of file uploads later on.
right now if my colleague needs to run the script from his computer, he have to manually change the value to his path.
You could use a suite file that contains a "setup" file to only change the file name in 1 place and the variable is shared across tests in the suite. You could also select an agreed up on place to store the files: c:\test_info\image.jpg.
Or you can make the file available by URL & not local, Unfortunately javascript prevents that for security: How to get the current file path in javascript
Unfortunately I can't think of any other good way unless you all have the same path in a home directory and could do something like ~/test_dir/photo.jpg

Load local image, modify it and save back to same file

File input allows user to access a local file from browser. Is it possible to load a local file given by file input, modify it and save it back to same local file? I know that HTML5 allows creating writeable filesystem, but basically it seems to be abstract directory.
For security reasons, I don't think the browser can overwrite the local file. Using the File-System API you could only copy the contents of the local file to the sandboxed File-System API directory(found under various obfuscated file names). All manipulation/saving would be done in AppData.
Perhaps displaying the modified image on the screen, right click, save-as to the given file location would also be suitable? (other than that I think you have to upload the image to a server and download it back again)

Can the code in a .crx chrome app have write access to the files within itself (the crx)?

I have a crx that has a number of files that I want to be able to change over time. For example, it might have this structure:
index.html
js/code.js
images/someimage.png
I want to be able to use ajax (or JSONP) to download a new image and overwrite image/someimage.png (after the crx has been installed into chrome). Is this possible?
No, you can not modify the application / extension data files directly.
But, you can store a downloaded image to chrome.storage, chrome.fileSystem, or chrome.syncFileSystem. At run time you can check to see if a downloaded image is there and swap out your image reference. E.g. use a dataURL or blob.

How can i get the path of file?

:image => StorageRoom::Image.new_with_filename(path)
I have to get the path of the image. So far i have specified the path manually and it worked and now i have put in heroku but it shows Load Error - No such file present.
How can i get the path value of the local system using browse button.
Your problem may not be related to path names, but to the fact that Heroku has a read-only file system. If you try to write files onto disk in a Heroku app, it simply doesn't work -- the file will not be saved.
The exception is the "temp" directory. You can save files there, but they are not guaranteed to persist for longer than the duration of a single request.
Is the file you are trying to open actually saved in your Git repo? If so, it will be on the disk in your Heroku app, and you should be able to open it.
To see what the filesystem layout looks like on your Heroku instance, you can create a controller method like:
render :inline => Dir['**/*'].inspect
File.expand_path
Reference : http://saaridev.blogspot.com/2006/11/ruby-finding-absolute-path-of-running.html
You don't need the full path. As far as file path in the client machine is concerned for file uploads, the path is irrelevant as it poses security risks for the user.
Most modern browsers don't send the file path for file uploads. You could get the path using Javascript or Flash but still I don't see the logic behind doing this.
When a user clicks on the submit button the browser should at least send you the file name with the file data together with a bunch of other information like the mime type. Your web server would either write the file to disk or process it in memory assuming you have near infinite memory resources. Look at the RFC 1867 for file uploads for more on this.