stavro / arc

:paperclip: Flexible file upload and attachment library for Elixir
1.16k stars 210 forks source link

How to delete temporary file automatically #256

Open zmcNotafraid opened 6 years ago

zmcNotafraid commented 6 years ago

I use local adapter and transform like this

  def transform(:file_format, _) do
    {:convert, "-format png", :png}
  end

Then I found it will generate a temporary file in temp folder.And I read the code in convert.ex and find this

    new_path = Arc.File.generate_temporary_path(file)

So I need to delete them manually. Do there have any solution to delete them automatically after upload successfully?

zmcNotafraid commented 6 years ago

I read the code that it invoke System.tmp_dir() method.

tmp_dir()
Writable temporary directory.

Returns a writable temporary directory. Searches for directories in the following order:

the directory named by the TMPDIR environment variable
the directory named by the TEMP environment variable
the directory named by the TMP environment variable
C:\TMP on Windows or /tmp on Unix
as a last resort, the current working directory
Returns nil if none of the above are writable.

So I export TMPDIR=/tmp/imagemagick. The temp file will save in this folder.And you need to delete them manually.

tielur commented 6 years ago

Any update on this? I'm seeing temporary files being left behind as well when using transform with convert

def transform(:thumb, _) do
  convert_opts =
    "-strip -thumbnail 250x250> -gravity center -background none -extent 250x250 -format png"

  {:convert, convert_opts, :png}
end
nicholasjhenry commented 5 years ago

I have a fork (https://github.com/stavro/arc/compare/master...hollar:hollar) that I'm maintaining that removes temporary files after processing. We were processing a large number of files in a small amount of time which ended up flooding the tmp directory. I can clean this up and create a PR if @stavro feels that this approach is the way to go. I'm also open to suggestions.