Not sure why this hidden file exists, it could be a branch of the X-send file or even wget (partial progress or something else).
Ideally, you should use a Tempfile to do this. The code is based on a comment about what you are doing. In addition, I use two gems, one for loading and the other for fastening. This way you do not need to create a folder at all, just a zip file directly. All zip content files will be deleted on their own. After downloading zip, just uninstall it. Here I should also mention that you may encounter a glitch somewhere, since send_file will transfer the transmission to the web server, and as such you do not handle rails to delete the file while it is still being served. So even with this, and it works well on the local host, I would strongly advise using a special garbage collector to collect data in production.
require 'open-uri' require 'zip/zip' zip_path = "#{Rails.root}/public/test.zip" urls_to_fetch = ['abc.com', 'xyz.com'] Zip::ZipFile.open(zip_path, Zip::ZipFile::CREATE) do |zipfile| urls_to_fetch.each_with_index do |url, index|
However, this should not be required. If you are doing something without Tempfiles, check the permissions that the rails runner has in the target directory.
The FileUtils documentation contains information about local security vulnerabilities when trying to delete files / folders.
source share