In video controller, create action. I am using FFMPEG to generate a
thumbnail of videos that are uploaded.
The tempfile is created as such:
def create
  ......
  dst = Tempfile.new(basename)
  dst.binmode
  system("ffmpeg -itsoffset -4 -i #{file.path} -y -vcodec mjpeg -
vframes 1 -an -f rawvideo #{File.expand_path(dst.path)}.png")
  ....
end
As you can see from above, ffmpeg outputs a file to the var dst which
is an instance of Tempfile. In console, when I do:
ls /var/folders/uL/uL0bYOOZEZaJH5E+BmDJVE+++TI/-Tmp-/
thumb20101111-989-1gflwhr.png
thumb20101111-989-1pt72my.png
thumb20101111-989-kjcsgd.png
thumb20101111-989-3ocf15.png
thumb20101111-989-10azwnn.png
thumb20101111-989-7x11w7.png
I see a bunch of files in the directory. It seems that rails did not
automatically delete these temp files. Should I manually delete these
files?
I am worried that, if my temp dir fills up with temp files, it''ll
eventually take up most of the server space...
Your thoughts on this matter?
-- 
You received this message because you are subscribed to the Google Groups
"Ruby on Rails: Talk" group.
To post to this group, send email to
rubyonrails-talk-/JYPxA39Uh5TLH3MbocFF+G/Ez6ZCGd0@public.gmane.org
To unsubscribe from this group, send email to
rubyonrails-talk+unsubscribe-/JYPxA39Uh5TLH3MbocFF+G/Ez6ZCGd0@public.gmane.org
For more options, visit this group at
http://groups.google.com/group/rubyonrails-talk?hl=en.
When you close the Tempfile, be sure to pass true for unlink_now. http://ruby-doc.org/stdlib/libdoc/tempfile/rdoc/classes/Tempfile.html#M004418 On Thu, Nov 11, 2010 at 2:33 PM, Christian Fazzini <christian.fazzini-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org> wrote:> In video controller, create action. I am using FFMPEG to generate a > thumbnail of videos that are uploaded. > > The tempfile is created as such: > > def create > ...... > dst = Tempfile.new(basename) > dst.binmode > > system("ffmpeg -itsoffset -4 -i #{file.path} -y -vcodec mjpeg - > vframes 1 -an -f rawvideo #{File.expand_path(dst.path)}.png") > .... > end > > > As you can see from above, ffmpeg outputs a file to the var dst which > is an instance of Tempfile. In console, when I do: > > ls /var/folders/uL/uL0bYOOZEZaJH5E+BmDJVE+++TI/-Tmp-/ > > thumb20101111-989-1gflwhr.png > thumb20101111-989-1pt72my.png > thumb20101111-989-kjcsgd.png > thumb20101111-989-3ocf15.png > thumb20101111-989-10azwnn.png > thumb20101111-989-7x11w7.png > > I see a bunch of files in the directory. It seems that rails did not > automatically delete these temp files. Should I manually delete these > files? > > I am worried that, if my temp dir fills up with temp files, it''ll > eventually take up most of the server space... > > Your thoughts on this matter? > > -- > You received this message because you are subscribed to the Google Groups "Ruby on Rails: Talk" group. > To post to this group, send email to rubyonrails-talk-/JYPxA39Uh5TLH3MbocFF+G/Ez6ZCGd0@public.gmane.org > To unsubscribe from this group, send email to rubyonrails-talk+unsubscribe@googlegroups.com. > For more options, visit this group at http://groups.google.com/group/rubyonrails-talk?hl=en. > >-- You received this message because you are subscribed to the Google Groups "Ruby on Rails: Talk" group. To post to this group, send email to rubyonrails-talk-/JYPxA39Uh5TLH3MbocFF+G/Ez6ZCGd0@public.gmane.org To unsubscribe from this group, send email to rubyonrails-talk+unsubscribe@googlegroups.com. For more options, visit this group at http://groups.google.com/group/rubyonrails-talk?hl=en.
Hi Brian, Just to keep things clear. By the end of the day, /var/folders/uL/ uL0bYOOZEZaJH5E+BmDJVE+++TI/-Tmp-/ <-- temp dir _IS_ supposed to be empty. Is this correct? On Nov 12, 3:35 am, Brian Troutwine <br...-MmYI4SXeg2M3tL2svhKZZQ@public.gmane.org> wrote:> When you close the Tempfile, be sure to pass true for unlink_now. > > http://ruby-doc.org/stdlib/libdoc/tempfile/rdoc/classes/Tempfile.html... > > On Thu, Nov 11, 2010 at 2:33 PM, Christian Fazzini > > <christian.fazz...-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org> wrote: > > In video controller, create action. I am using FFMPEG to generate a > > thumbnail of videos that are uploaded. > > > The tempfile is created as such: > > > def create > > ...... > > dst = Tempfile.new(basename) > > dst.binmode > > > system("ffmpeg -itsoffset -4 -i #{file.path} -y -vcodec mjpeg - > > vframes 1 -an -f rawvideo #{File.expand_path(dst.path)}.png") > > .... > > end > > > As you can see from above, ffmpeg outputs a file to the var dst which > > is an instance of Tempfile. In console, when I do: > > > ls /var/folders/uL/uL0bYOOZEZaJH5E+BmDJVE+++TI/-Tmp-/ > > > thumb20101111-989-1gflwhr.png > > thumb20101111-989-1pt72my.png > > thumb20101111-989-kjcsgd.png > > thumb20101111-989-3ocf15.png > > thumb20101111-989-10azwnn.png > > thumb20101111-989-7x11w7.png > > > I see a bunch of files in the directory. It seems that rails did not > > automatically delete these temp files. Should I manually delete these > > files? > > > I am worried that, if my temp dir fills up with temp files, it''ll > > eventually take up most of the server space... > > > Your thoughts on this matter? > > > -- > > You received this message because you are subscribed to the Google Groups "Ruby on Rails: Talk" group. > > To post to this group, send email to rubyonrails-talk-/JYPxA39Uh5TLH3MbocFF+G/Ez6ZCGd0@public.gmane.org > > To unsubscribe from this group, send email to rubyonrails-talk+unsubscribe-/JYPxA39Uh5TLH3MbocFF+G/Ez6ZCGd0@public.gmane.org > > For more options, visit this group athttp://groups.google.com/group/rubyonrails-talk?hl=en. > >-- You received this message because you are subscribed to the Google Groups "Ruby on Rails: Talk" group. To post to this group, send email to rubyonrails-talk-/JYPxA39Uh5TLH3MbocFF+G/Ez6ZCGd0@public.gmane.org To unsubscribe from this group, send email to rubyonrails-talk+unsubscribe@googlegroups.com. For more options, visit this group at http://groups.google.com/group/rubyonrails-talk?hl=en.
Hi Christian, Not by the end of the day, no. Each tempfile will be unlinked as soon as you close it. Your example code didn''t have the line> dst.close(unlink_now=true)in it. You may also use dst.close!() to the same effect. -- Brian On Thu, Nov 11, 2010 at 2:49 PM, Christian Fazzini <christian.fazzini-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org> wrote:> Hi Brian, > > Just to keep things clear. By the end of the day, /var/folders/uL/ > uL0bYOOZEZaJH5E+BmDJVE+++TI/-Tmp-/ <-- temp dir _IS_ supposed to be > empty. Is this correct? > > On Nov 12, 3:35 am, Brian Troutwine <br...-MmYI4SXeg2M3tL2svhKZZQ@public.gmane.org> wrote: >> When you close the Tempfile, be sure to pass true for unlink_now. >> >> http://ruby-doc.org/stdlib/libdoc/tempfile/rdoc/classes/Tempfile.html... >> >> On Thu, Nov 11, 2010 at 2:33 PM, Christian Fazzini >> >> <christian.fazz...-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org> wrote: >> > In video controller, create action. I am using FFMPEG to generate a >> > thumbnail of videos that are uploaded. >> >> > The tempfile is created as such: >> >> > def create >> > ...... >> > dst = Tempfile.new(basename) >> > dst.binmode >> >> > system("ffmpeg -itsoffset -4 -i #{file.path} -y -vcodec mjpeg - >> > vframes 1 -an -f rawvideo #{File.expand_path(dst.path)}.png") >> > .... >> > end >> >> > As you can see from above, ffmpeg outputs a file to the var dst which >> > is an instance of Tempfile. In console, when I do: >> >> > ls /var/folders/uL/uL0bYOOZEZaJH5E+BmDJVE+++TI/-Tmp-/ >> >> > thumb20101111-989-1gflwhr.png >> > thumb20101111-989-1pt72my.png >> > thumb20101111-989-kjcsgd.png >> > thumb20101111-989-3ocf15.png >> > thumb20101111-989-10azwnn.png >> > thumb20101111-989-7x11w7.png >> >> > I see a bunch of files in the directory. It seems that rails did not >> > automatically delete these temp files. Should I manually delete these >> > files? >> >> > I am worried that, if my temp dir fills up with temp files, it''ll >> > eventually take up most of the server space... >> >> > Your thoughts on this matter? >> >> > -- >> > You received this message because you are subscribed to the Google Groups "Ruby on Rails: Talk" group. >> > To post to this group, send email to rubyonrails-talk-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org. >> > To unsubscribe from this group, send email to rubyonrails-talk+unsubscribe-/JYPxA39Uh5TLH3MbocFF+G/Ez6ZCGd0@public.gmane.org >> > For more options, visit this group athttp://groups.google.com/group/rubyonrails-talk?hl=en. >> >> > > -- > You received this message because you are subscribed to the Google Groups "Ruby on Rails: Talk" group. > To post to this group, send email to rubyonrails-talk-/JYPxA39Uh5TLH3MbocFF+G/Ez6ZCGd0@public.gmane.org > To unsubscribe from this group, send email to rubyonrails-talk+unsubscribe@googlegroups.com. > For more options, visit this group at http://groups.google.com/group/rubyonrails-talk?hl=en. > >-- You received this message because you are subscribed to the Google Groups "Ruby on Rails: Talk" group. To post to this group, send email to rubyonrails-talk-/JYPxA39Uh5TLH3MbocFF+G/Ez6ZCGd0@public.gmane.org To unsubscribe from this group, send email to rubyonrails-talk+unsubscribe@googlegroups.com. For more options, visit this group at http://groups.google.com/group/rubyonrails-talk?hl=en.
Ok that makes sense. Thanks Brian.
On the same topic...
How would I create a temp file with .png extension in the end.
tmp = Tempfile.new([ ''thumb'', ''png''
].compact.join("."))
Whenever it creates a temp file, it creates it as such:
thumb.png20101111-989-1pt72my, instead of
thumb20101111-989-1pt72my.png
If I try to save this via Active Record, with
@video.attachment_thumbnail
File.open("#{File.expand_path(tmp.path)}"),
It will save the file in the file system without the extension, which
makes it impossible to read on the browser, unless I explicitly set
the extension.
On Nov 12, 3:54 am, Brian Troutwine
<br...-MmYI4SXeg2M3tL2svhKZZQ@public.gmane.org>
wrote:> Hi Christian,
>
> Not by the end of the day, no. Each tempfile will be unlinked as soon
> as you close it. Your example code didn''t have the line
>
> > dst.close(unlink_now=true)
>
> in it. You may also use dst.close!() to the same effect.
>
> --
> Brian
>
> On Thu, Nov 11, 2010 at 2:49 PM, Christian Fazzini
>
> <christian.fazz...-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org> wrote:
> > Hi Brian,
>
> > Just to keep things clear. By the end of the day, /var/folders/uL/
> > uL0bYOOZEZaJH5E+BmDJVE+++TI/-Tmp-/  <-- temp dir _IS_ supposed to
be
> > empty. Is this correct?
>
> > On Nov 12, 3:35 am, Brian Troutwine
<br...-MmYI4SXeg2M3tL2svhKZZQ@public.gmane.org> wrote:
> >> When you close the Tempfile, be sure to pass true for unlink_now.
>
>
>>http://ruby-doc.org/stdlib/libdoc/tempfile/rdoc/classes/Tempfile.html...
>
> >> On Thu, Nov 11, 2010 at 2:33 PM, Christian Fazzini
>
> >> <christian.fazz...-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org>
wrote:
> >> > In video controller, create action. I am using FFMPEG to
generate a
> >> > thumbnail of videos that are uploaded.
>
> >> > The tempfile is created as such:
>
> >> > def create
> >> >  ......
> >> >  dst = Tempfile.new(basename)
> >> >  dst.binmode
>
> >> >  system("ffmpeg -itsoffset -4 -i #{file.path} -y -vcodec
mjpeg -
> >> > vframes 1 -an -f rawvideo
#{File.expand_path(dst.path)}.png")
> >> >  ....
> >> > end
>
> >> > As you can see from above, ffmpeg outputs a file to the var
dst which
> >> > is an instance of Tempfile. In console, when I do:
>
> >> > ls /var/folders/uL/uL0bYOOZEZaJH5E+BmDJVE+++TI/-Tmp-/
>
> >> > thumb20101111-989-1gflwhr.png
> >> > thumb20101111-989-1pt72my.png
> >> > thumb20101111-989-kjcsgd.png
> >> > thumb20101111-989-3ocf15.png
> >> > thumb20101111-989-10azwnn.png
> >> > thumb20101111-989-7x11w7.png
>
> >> > I see a bunch of files in the directory. It seems that rails
did not
> >> > automatically delete these temp files. Should I manually
delete these
> >> > files?
>
> >> > I am worried that, if my temp dir fills up with temp files,
it''ll
> >> > eventually take up most of the server space...
>
> >> > Your thoughts on this matter?
>
> >> > --
> >> > You received this message because you are subscribed to the
Google Groups "Ruby on Rails: Talk" group.
> >> > To post to this group, send email to
rubyonrails-talk@googlegroups.com.
> >> > To unsubscribe from this group, send email to
rubyonrails-talk+unsubscribe-/JYPxA39Uh5TLH3MbocFF+G/Ez6ZCGd0@public.gmane.org
> >> > For more options, visit this group
athttp://groups.google.com/group/rubyonrails-talk?hl=en.
>
> > --
> > You received this message because you are subscribed to the Google
Groups "Ruby on Rails: Talk" group.
> > To post to this group, send email to
rubyonrails-talk-/JYPxA39Uh5TLH3MbocFF+G/Ez6ZCGd0@public.gmane.org
> > To unsubscribe from this group, send email to
rubyonrails-talk+unsubscribe-/JYPxA39Uh5TLH3MbocFF+G/Ez6ZCGd0@public.gmane.org
> > For more options, visit this group
athttp://groups.google.com/group/rubyonrails-talk?hl=en.
>
>
-- 
You received this message because you are subscribed to the Google Groups
"Ruby on Rails: Talk" group.
To post to this group, send email to
rubyonrails-talk-/JYPxA39Uh5TLH3MbocFF+G/Ez6ZCGd0@public.gmane.org
To unsubscribe from this group, send email to
rubyonrails-talk+unsubscribe@googlegroups.com.
For more options, visit this group at
http://groups.google.com/group/rubyonrails-talk?hl=en.
I''m confused. You''re creating a tempfile and then keeping a reference to it in your database? On Thu, Nov 11, 2010 at 3:06 PM, Christian Fazzini <christian.fazzini-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org> wrote:> Ok that makes sense. Thanks Brian. > > On the same topic... > > How would I create a temp file with .png extension in the end. > > tmp = Tempfile.new([ ''thumb'', ''png'' ].compact.join("."))You can''t use Tempfile to do this. Well, you _can_ but you''ll need to close the file--without unlinking it!--and then move the file created to the new location you want. At that points, you''re better off just giving thumbnails a sequential identifier, or use their hash. Destroy the thumbnail file once you no longer need it.> Whenever it creates a temp file, it creates it as such: > thumb.png20101111-989-1pt72my, instead of > thumb20101111-989-1pt72my.png > > If I try to save this via Active Record, with > > @video.attachment_thumbnail > File.open("#{File.expand_path(tmp.path)}"), > > It will save the file in the file system without the extension, which > makes it impossible to read on the browser, unless I explicitly set > the extension. > > On Nov 12, 3:54 am, Brian Troutwine <br...-MmYI4SXeg2M3tL2svhKZZQ@public.gmane.org> wrote: >> Hi Christian, >> >> Not by the end of the day, no. Each tempfile will be unlinked as soon >> as you close it. Your example code didn''t have the line >> >> > dst.close(unlink_now=true) >> >> in it. You may also use dst.close!() to the same effect. >> >> -- >> Brian >> >> On Thu, Nov 11, 2010 at 2:49 PM, Christian Fazzini >> >> <christian.fazz...-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org> wrote: >> > Hi Brian, >> >> > Just to keep things clear. By the end of the day, /var/folders/uL/ >> > uL0bYOOZEZaJH5E+BmDJVE+++TI/-Tmp-/ <-- temp dir _IS_ supposed to be >> > empty. Is this correct? >> >> > On Nov 12, 3:35 am, Brian Troutwine <br...-MmYI4SXeg2M3tL2svhKZZQ@public.gmane.org> wrote: >> >> When you close the Tempfile, be sure to pass true for unlink_now. >> >> >>http://ruby-doc.org/stdlib/libdoc/tempfile/rdoc/classes/Tempfile.html... >> >> >> On Thu, Nov 11, 2010 at 2:33 PM, Christian Fazzini >> >> >> <christian.fazz...-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org> wrote: >> >> > In video controller, create action. I am using FFMPEG to generate a >> >> > thumbnail of videos that are uploaded. >> >> >> > The tempfile is created as such: >> >> >> > def create >> >> > ...... >> >> > dst = Tempfile.new(basename) >> >> > dst.binmode >> >> >> > system("ffmpeg -itsoffset -4 -i #{file.path} -y -vcodec mjpeg - >> >> > vframes 1 -an -f rawvideo #{File.expand_path(dst.path)}.png") >> >> > .... >> >> > end >> >> >> > As you can see from above, ffmpeg outputs a file to the var dst which >> >> > is an instance of Tempfile. In console, when I do: >> >> >> > ls /var/folders/uL/uL0bYOOZEZaJH5E+BmDJVE+++TI/-Tmp-/ >> >> >> > thumb20101111-989-1gflwhr.png >> >> > thumb20101111-989-1pt72my.png >> >> > thumb20101111-989-kjcsgd.png >> >> > thumb20101111-989-3ocf15.png >> >> > thumb20101111-989-10azwnn.png >> >> > thumb20101111-989-7x11w7.png >> >> >> > I see a bunch of files in the directory. It seems that rails did not >> >> > automatically delete these temp files. Should I manually delete these >> >> > files? >> >> >> > I am worried that, if my temp dir fills up with temp files, it''ll >> >> > eventually take up most of the server space... >> >> >> > Your thoughts on this matter? >> >> >> > -- >> >> > You received this message because you are subscribed to the Google Groups "Ruby on Rails: Talk" group. >> >> > To post to this group, send email to rubyonrails-talk@googlegroups.com. >> >> > To unsubscribe from this group, send email to rubyonrails-talk+unsubscribe-/JYPxA39Uh5TLH3MbocFF+G/Ez6ZCGd0@public.gmane.org >> >> > For more options, visit this group athttp://groups.google.com/group/rubyonrails-talk?hl=en. >> >> > -- >> > You received this message because you are subscribed to the Google Groups "Ruby on Rails: Talk" group. >> > To post to this group, send email to rubyonrails-talk-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org. >> > To unsubscribe from this group, send email to rubyonrails-talk+unsubscribe-/JYPxA39Uh5TLH3MbocFF+G/Ez6ZCGd0@public.gmane.org >> > For more options, visit this group athttp://groups.google.com/group/rubyonrails-talk?hl=en. >> >> > > -- > You received this message because you are subscribed to the Google Groups "Ruby on Rails: Talk" group. > To post to this group, send email to rubyonrails-talk-/JYPxA39Uh5TLH3MbocFF+G/Ez6ZCGd0@public.gmane.org > To unsubscribe from this group, send email to rubyonrails-talk+unsubscribe@googlegroups.com. > For more options, visit this group at http://groups.google.com/group/rubyonrails-talk?hl=en. > >-- You received this message because you are subscribed to the Google Groups "Ruby on Rails: Talk" group. To post to this group, send email to rubyonrails-talk-/JYPxA39Uh5TLH3MbocFF+G/Ez6ZCGd0@public.gmane.org To unsubscribe from this group, send email to rubyonrails-talk+unsubscribe@googlegroups.com. For more options, visit this group at http://groups.google.com/group/rubyonrails-talk?hl=en.
No, the following saves the temp file. @video.attachment_thumbnail File.open(File.expand_path(tmp.path)) However, File.expand_path(tmp.path) saves the file in the file system as thumb.png20101111-989-1pt72my Ideally, I would like it to save it as thumb20101111-989-1pt72my.png or, better, just thumb.png On Nov 12, 4:12 am, Brian Troutwine <br...-MmYI4SXeg2M3tL2svhKZZQ@public.gmane.org> wrote:> I''m confused. You''re creating a tempfile and then keeping a reference > to it in your database? > > On Thu, Nov 11, 2010 at 3:06 PM, Christian Fazzini > > <christian.fazz...-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org> wrote: > > Ok that makes sense. Thanks Brian. > > > On the same topic... > > > How would I create a temp file with .png extension in the end. > > > tmp = Tempfile.new([ ''thumb'', ''png'' ].compact.join(".")) > > You can''t use Tempfile to do this. Well, you _can_ but you''ll need to > close the file--without unlinking it!--and then move the file created > to the new location you want. At that points, you''re better off just > giving thumbnails a sequential identifier, or use their hash. Destroy > the thumbnail file once you no longer need it. > > > Whenever it creates a temp file, it creates it as such: > > thumb.png20101111-989-1pt72my, instead of > > thumb20101111-989-1pt72my.png > > > If I try to save this via Active Record, with > > > @video.attachment_thumbnail > > File.open("#{File.expand_path(tmp.path)}"), > > > It will save the file in the file system without the extension, which > > makes it impossible to read on the browser, unless I explicitly set > > the extension. > > > On Nov 12, 3:54 am, Brian Troutwine <br...-MmYI4SXeg2M3tL2svhKZZQ@public.gmane.org> wrote: > >> Hi Christian, > > >> Not by the end of the day, no. Each tempfile will be unlinked as soon > >> as you close it. Your example code didn''t have the line > > >> > dst.close(unlink_now=true) > > >> in it. You may also use dst.close!() to the same effect. > > >> -- > >> Brian > > >> On Thu, Nov 11, 2010 at 2:49 PM, Christian Fazzini > > >> <christian.fazz...-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org> wrote: > >> > Hi Brian, > > >> > Just to keep things clear. By the end of the day, /var/folders/uL/ > >> > uL0bYOOZEZaJH5E+BmDJVE+++TI/-Tmp-/ <-- temp dir _IS_ supposed to be > >> > empty. Is this correct? > > >> > On Nov 12, 3:35 am, Brian Troutwine <br...-MmYI4SXeg2M3tL2svhKZZQ@public.gmane.org> wrote: > >> >> When you close the Tempfile, be sure to pass true for unlink_now. > > >> >>http://ruby-doc.org/stdlib/libdoc/tempfile/rdoc/classes/Tempfile.html... > > >> >> On Thu, Nov 11, 2010 at 2:33 PM, Christian Fazzini > > >> >> <christian.fazz...-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org> wrote: > >> >> > In video controller, create action. I am using FFMPEG to generate a > >> >> > thumbnail of videos that are uploaded. > > >> >> > The tempfile is created as such: > > >> >> > def create > >> >> > ...... > >> >> > dst = Tempfile.new(basename) > >> >> > dst.binmode > > >> >> > system("ffmpeg -itsoffset -4 -i #{file.path} -y -vcodec mjpeg - > >> >> > vframes 1 -an -f rawvideo #{File.expand_path(dst.path)}.png") > >> >> > .... > >> >> > end > > >> >> > As you can see from above, ffmpeg outputs a file to the var dst which > >> >> > is an instance of Tempfile. In console, when I do: > > >> >> > ls /var/folders/uL/uL0bYOOZEZaJH5E+BmDJVE+++TI/-Tmp-/ > > >> >> > thumb20101111-989-1gflwhr.png > >> >> > thumb20101111-989-1pt72my.png > >> >> > thumb20101111-989-kjcsgd.png > >> >> > thumb20101111-989-3ocf15.png > >> >> > thumb20101111-989-10azwnn.png > >> >> > thumb20101111-989-7x11w7.png > > >> >> > I see a bunch of files in the directory. It seems that rails did not > >> >> > automatically delete these temp files. Should I manually delete these > >> >> > files? > > >> >> > I am worried that, if my temp dir fills up with temp files, it''ll > >> >> > eventually take up most of the server space... > > >> >> > Your thoughts on this matter? > > >> >> > -- > >> >> > You received this message because you are subscribed to the Google Groups "Ruby on Rails: Talk" group. > >> >> > To post to this group, send email to rubyonrails-talk@googlegroups.com. > >> >> > To unsubscribe from this group, send email to rubyonrails-talk+unsubscribe-/JYPxA39Uh5TLH3MbocFF+G/Ez6ZCGd0@public.gmane.org > >> >> > For more options, visit this group athttp://groups.google.com/group/rubyonrails-talk?hl=en. > > >> > -- > >> > You received this message because you are subscribed to the Google Groups "Ruby on Rails: Talk" group. > >> > To post to this group, send email to rubyonrails-talk@googlegroups.com. > >> > To unsubscribe from this group, send email to rubyonrails-talk+unsubscribe-/JYPxA39Uh5TLH3MbocFF+G/Ez6ZCGd0@public.gmane.org > >> > For more options, visit this group athttp://groups.google.com/group/rubyonrails-talk?hl=en. > > > -- > > You received this message because you are subscribed to the Google Groups "Ruby on Rails: Talk" group. > > To post to this group, send email to rubyonrails-talk-/JYPxA39Uh5TLH3MbocFF+G/Ez6ZCGd0@public.gmane.org > > To unsubscribe from this group, send email to rubyonrails-talk+unsubscribe-/JYPxA39Uh5TLH3MbocFF+G/Ez6ZCGd0@public.gmane.org > > For more options, visit this group athttp://groups.google.com/group/rubyonrails-talk?hl=en. > >-- You received this message because you are subscribed to the Google Groups "Ruby on Rails: Talk" group. To post to this group, send email to rubyonrails-talk-/JYPxA39Uh5TLH3MbocFF+G/Ez6ZCGd0@public.gmane.org To unsubscribe from this group, send email to rubyonrails-talk+unsubscribe@googlegroups.com. For more options, visit this group at http://groups.google.com/group/rubyonrails-talk?hl=en.
Basically I need to create a new tempfile with a png extension. Is this possible? On Nov 12, 4:21 am, Christian Fazzini <christian.fazz...-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org> wrote:> No, the following saves the temp file. > > @video.attachment_thumbnail > File.open(File.expand_path(tmp.path)) > > However, File.expand_path(tmp.path) saves the file in the file system > as thumb.png20101111-989-1pt72my > > Ideally, I would like it to save it as thumb20101111-989-1pt72my.png > or, better, just thumb.png > > On Nov 12, 4:12 am, Brian Troutwine <br...-MmYI4SXeg2M3tL2svhKZZQ@public.gmane.org> wrote: > > > I''m confused. You''re creating a tempfile and then keeping a reference > > to it in your database? > > > On Thu, Nov 11, 2010 at 3:06 PM, Christian Fazzini > > > <christian.fazz...-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org> wrote: > > > Ok that makes sense. Thanks Brian. > > > > On the same topic... > > > > How would I create a temp file with .png extension in the end. > > > > tmp = Tempfile.new([ ''thumb'', ''png'' ].compact.join(".")) > > > You can''t use Tempfile to do this. Well, you _can_ but you''ll need to > > close the file--without unlinking it!--and then move the file created > > to the new location you want. At that points, you''re better off just > > giving thumbnails a sequential identifier, or use their hash. Destroy > > the thumbnail file once you no longer need it. > > > > Whenever it creates a temp file, it creates it as such: > > > thumb.png20101111-989-1pt72my, instead of > > > thumb20101111-989-1pt72my.png > > > > If I try to save this via Active Record, with > > > > @video.attachment_thumbnail > > > File.open("#{File.expand_path(tmp.path)}"), > > > > It will save the file in the file system without the extension, which > > > makes it impossible to read on the browser, unless I explicitly set > > > the extension. > > > > On Nov 12, 3:54 am, Brian Troutwine <br...-MmYI4SXeg2M3tL2svhKZZQ@public.gmane.org> wrote: > > >> Hi Christian, > > > >> Not by the end of the day, no. Each tempfile will be unlinked as soon > > >> as you close it. Your example code didn''t have the line > > > >> > dst.close(unlink_now=true) > > > >> in it. You may also use dst.close!() to the same effect. > > > >> -- > > >> Brian > > > >> On Thu, Nov 11, 2010 at 2:49 PM, Christian Fazzini > > > >> <christian.fazz...-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org> wrote: > > >> > Hi Brian, > > > >> > Just to keep things clear. By the end of the day, /var/folders/uL/ > > >> > uL0bYOOZEZaJH5E+BmDJVE+++TI/-Tmp-/ <-- temp dir _IS_ supposed to be > > >> > empty. Is this correct? > > > >> > On Nov 12, 3:35 am, Brian Troutwine <br...-MmYI4SXeg2M3tL2svhKZZQ@public.gmane.org> wrote: > > >> >> When you close the Tempfile, be sure to pass true for unlink_now. > > > >> >>http://ruby-doc.org/stdlib/libdoc/tempfile/rdoc/classes/Tempfile.html... > > > >> >> On Thu, Nov 11, 2010 at 2:33 PM, Christian Fazzini > > > >> >> <christian.fazz...-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org> wrote: > > >> >> > In video controller, create action. I am using FFMPEG to generate a > > >> >> > thumbnail of videos that are uploaded. > > > >> >> > The tempfile is created as such: > > > >> >> > def create > > >> >> > ...... > > >> >> > dst = Tempfile.new(basename) > > >> >> > dst.binmode > > > >> >> > system("ffmpeg -itsoffset -4 -i #{file.path} -y -vcodec mjpeg - > > >> >> > vframes 1 -an -f rawvideo #{File.expand_path(dst.path)}.png") > > >> >> > .... > > >> >> > end > > > >> >> > As you can see from above, ffmpeg outputs a file to the var dst which > > >> >> > is an instance of Tempfile. In console, when I do: > > > >> >> > ls /var/folders/uL/uL0bYOOZEZaJH5E+BmDJVE+++TI/-Tmp-/ > > > >> >> > thumb20101111-989-1gflwhr.png > > >> >> > thumb20101111-989-1pt72my.png > > >> >> > thumb20101111-989-kjcsgd.png > > >> >> > thumb20101111-989-3ocf15.png > > >> >> > thumb20101111-989-10azwnn.png > > >> >> > thumb20101111-989-7x11w7.png > > > >> >> > I see a bunch of files in the directory. It seems that rails did not > > >> >> > automatically delete these temp files. Should I manually delete these > > >> >> > files? > > > >> >> > I am worried that, if my temp dir fills up with temp files, it''ll > > >> >> > eventually take up most of the server space... > > > >> >> > Your thoughts on this matter? > > > >> >> > -- > > >> >> > You received this message because you are subscribed to the Google Groups "Ruby on Rails: Talk" group. > > >> >> > To post to this group, send email to rubyonrails-talk@googlegroups.com. > > >> >> > To unsubscribe from this group, send email to rubyonrails-talk+unsubscribe-/JYPxA39Uh5TLH3MbocFF+G/Ez6ZCGd0@public.gmane.org > > >> >> > For more options, visit this group athttp://groups.google.com/group/rubyonrails-talk?hl=en. > > > >> > -- > > >> > You received this message because you are subscribed to the Google Groups "Ruby on Rails: Talk" group. > > >> > To post to this group, send email to rubyonrails-talk@googlegroups.com. > > >> > To unsubscribe from this group, send email to rubyonrails-talk+unsubscribe-/JYPxA39Uh5TLH3MbocFF+G/Ez6ZCGd0@public.gmane.org > > >> > For more options, visit this group athttp://groups.google.com/group/rubyonrails-talk?hl=en. > > > > -- > > > You received this message because you are subscribed to the Google Groups "Ruby on Rails: Talk" group. > > > To post to this group, send email to rubyonrails-talk-/JYPxA39Uh4Ykp1iOSErHA@public.gmane.orgm. > > > To unsubscribe from this group, send email to rubyonrails-talk+unsubscribe-/JYPxA39Uh5TLH3MbocFF+G/Ez6ZCGd0@public.gmane.org > > > For more options, visit this group athttp://groups.google.com/group/rubyonrails-talk?hl=en. > >-- You received this message because you are subscribed to the Google Groups "Ruby on Rails: Talk" group. To post to this group, send email to rubyonrails-talk-/JYPxA39Uh5TLH3MbocFF+G/Ez6ZCGd0@public.gmane.org To unsubscribe from this group, send email to rubyonrails-talk+unsubscribe@googlegroups.com. For more options, visit this group at http://groups.google.com/group/rubyonrails-talk?hl=en.
On Thu, Nov 11, 2010 at 3:21 PM, Christian Fazzini <christian.fazzini-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org> wrote:> No, the following saves the temp file. > > @video.attachment_thumbnail > File.open(File.expand_path(tmp.path))Ah, apologies.> However, File.expand_path(tmp.path) saves the file in the file system > as thumb.png20101111-989-1pt72my > Ideally, I would like it to save it as thumb20101111-989-1pt72my.pngOkay, so you''ve got this:>>> tmp = Tempfile.new([ ''thumb'', ''png'' ].compact.join("."))The documentation for Tempfile states that .new "creates a temporary file of mode 0600 in the temporary directory whose name is basename.pid.n and opens with mode "w+". A Tempfile object works just like a File object." The computer is doing exactly what you tell it to do.> or, better, just thumb.pngWould not this conflict if you have multiple users uploading files at the same time?> On Nov 12, 4:12 am, Brian Troutwine <br...-MmYI4SXeg2M3tL2svhKZZQ@public.gmane.org> wrote: >> I''m confused. You''re creating a tempfile and then keeping a reference >> to it in your database? >> >> On Thu, Nov 11, 2010 at 3:06 PM, Christian Fazzini >> >> <christian.fazz...-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org> wrote: >> > Ok that makes sense. Thanks Brian. >> >> > On the same topic... >> >> > How would I create a temp file with .png extension in the end. >> >> > tmp = Tempfile.new([ ''thumb'', ''png'' ].compact.join(".")) >> >> You can''t use Tempfile to do this. Well, you _can_ but you''ll need to >> close the file--without unlinking it!--and then move the file created >> to the new location you want. At that points, you''re better off just >> giving thumbnails a sequential identifier, or use their hash. Destroy >> the thumbnail file once you no longer need it. >> >> > Whenever it creates a temp file, it creates it as such: >> > thumb.png20101111-989-1pt72my, instead of >> > thumb20101111-989-1pt72my.png >> >> > If I try to save this via Active Record, with >> >> > @video.attachment_thumbnail >> > File.open("#{File.expand_path(tmp.path)}"), >> >> > It will save the file in the file system without the extension, which >> > makes it impossible to read on the browser, unless I explicitly set >> > the extension. >> >> > On Nov 12, 3:54 am, Brian Troutwine <br...-MmYI4SXeg2M3tL2svhKZZQ@public.gmane.org> wrote: >> >> Hi Christian, >> >> >> Not by the end of the day, no. Each tempfile will be unlinked as soon >> >> as you close it. Your example code didn''t have the line >> >> >> > dst.close(unlink_now=true) >> >> >> in it. You may also use dst.close!() to the same effect. >> >> >> -- >> >> Brian >> >> >> On Thu, Nov 11, 2010 at 2:49 PM, Christian Fazzini >> >> >> <christian.fazz...-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org> wrote: >> >> > Hi Brian, >> >> >> > Just to keep things clear. By the end of the day, /var/folders/uL/ >> >> > uL0bYOOZEZaJH5E+BmDJVE+++TI/-Tmp-/ <-- temp dir _IS_ supposed to be >> >> > empty. Is this correct? >> >> >> > On Nov 12, 3:35 am, Brian Troutwine <br...-MmYI4SXeg2M3tL2svhKZZQ@public.gmane.org> wrote: >> >> >> When you close the Tempfile, be sure to pass true for unlink_now. >> >> >> >>http://ruby-doc.org/stdlib/libdoc/tempfile/rdoc/classes/Tempfile.html... >> >> >> >> On Thu, Nov 11, 2010 at 2:33 PM, Christian Fazzini >> >> >> >> <christian.fazz...-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org> wrote: >> >> >> > In video controller, create action. I am using FFMPEG to generate a >> >> >> > thumbnail of videos that are uploaded. >> >> >> >> > The tempfile is created as such: >> >> >> >> > def create >> >> >> > ...... >> >> >> > dst = Tempfile.new(basename) >> >> >> > dst.binmode >> >> >> >> > system("ffmpeg -itsoffset -4 -i #{file.path} -y -vcodec mjpeg - >> >> >> > vframes 1 -an -f rawvideo #{File.expand_path(dst.path)}.png") >> >> >> > .... >> >> >> > end >> >> >> >> > As you can see from above, ffmpeg outputs a file to the var dst which >> >> >> > is an instance of Tempfile. In console, when I do: >> >> >> >> > ls /var/folders/uL/uL0bYOOZEZaJH5E+BmDJVE+++TI/-Tmp-/ >> >> >> >> > thumb20101111-989-1gflwhr.png >> >> >> > thumb20101111-989-1pt72my.png >> >> >> > thumb20101111-989-kjcsgd.png >> >> >> > thumb20101111-989-3ocf15.png >> >> >> > thumb20101111-989-10azwnn.png >> >> >> > thumb20101111-989-7x11w7.png >> >> >> >> > I see a bunch of files in the directory. It seems that rails did not >> >> >> > automatically delete these temp files. Should I manually delete these >> >> >> > files? >> >> >> >> > I am worried that, if my temp dir fills up with temp files, it''ll >> >> >> > eventually take up most of the server space... >> >> >> >> > Your thoughts on this matter? >> >> >> >> > -- >> >> >> > You received this message because you are subscribed to the Google Groups "Ruby on Rails: Talk" group. >> >> >> > To post to this group, send email to rubyonrails-talk@googlegroups.com. >> >> >> > To unsubscribe from this group, send email to rubyonrails-talk+unsubscribe-/JYPxA39Uh5TLH3MbocFF+G/Ez6ZCGd0@public.gmane.org >> >> >> > For more options, visit this group athttp://groups.google.com/group/rubyonrails-talk?hl=en. >> >> >> > -- >> >> > You received this message because you are subscribed to the Google Groups "Ruby on Rails: Talk" group. >> >> > To post to this group, send email to rubyonrails-talk@googlegroups.com. >> >> > To unsubscribe from this group, send email to rubyonrails-talk+unsubscribe-/JYPxA39Uh5TLH3MbocFF+G/Ez6ZCGd0@public.gmane.org >> >> > For more options, visit this group athttp://groups.google.com/group/rubyonrails-talk?hl=en. >> >> > -- >> > You received this message because you are subscribed to the Google Groups "Ruby on Rails: Talk" group. >> > To post to this group, send email to rubyonrails-talk-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org. >> > To unsubscribe from this group, send email to rubyonrails-talk+unsubscribe-/JYPxA39Uh5TLH3MbocFF+G/Ez6ZCGd0@public.gmane.org >> > For more options, visit this group athttp://groups.google.com/group/rubyonrails-talk?hl=en. >> >> > > -- > You received this message because you are subscribed to the Google Groups "Ruby on Rails: Talk" group. > To post to this group, send email to rubyonrails-talk-/JYPxA39Uh5TLH3MbocFF+G/Ez6ZCGd0@public.gmane.org > To unsubscribe from this group, send email to rubyonrails-talk+unsubscribe@googlegroups.com. > For more options, visit this group at http://groups.google.com/group/rubyonrails-talk?hl=en. > >-- You received this message because you are subscribed to the Google Groups "Ruby on Rails: Talk" group. To post to this group, send email to rubyonrails-talk-/JYPxA39Uh5TLH3MbocFF+G/Ez6ZCGd0@public.gmane.org To unsubscribe from this group, send email to rubyonrails-talk+unsubscribe@googlegroups.com. For more options, visit this group at http://groups.google.com/group/rubyonrails-talk?hl=en.
Yes, but not with Tempfile. Hash the video data, store your thumbnail as $HASH.png, keep a reference to this file and be sure to delete it when the user performs such actions as make the thumbnail no longer necessary. On Thu, Nov 11, 2010 at 3:29 PM, Christian Fazzini <christian.fazzini-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org> wrote:> Basically I need to create a new tempfile with a png extension. Is > this possible? > > On Nov 12, 4:21 am, Christian Fazzini <christian.fazz...-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org> > wrote: >> No, the following saves the temp file. >> >> @video.attachment_thumbnail >> File.open(File.expand_path(tmp.path)) >> >> However, File.expand_path(tmp.path) saves the file in the file system >> as thumb.png20101111-989-1pt72my >> >> Ideally, I would like it to save it as thumb20101111-989-1pt72my.png >> or, better, just thumb.png >> >> On Nov 12, 4:12 am, Brian Troutwine <br...-MmYI4SXeg2M3tL2svhKZZQ@public.gmane.org> wrote: >> >> > I''m confused. You''re creating a tempfile and then keeping a reference >> > to it in your database? >> >> > On Thu, Nov 11, 2010 at 3:06 PM, Christian Fazzini >> >> > <christian.fazz...-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org> wrote: >> > > Ok that makes sense. Thanks Brian. >> >> > > On the same topic... >> >> > > How would I create a temp file with .png extension in the end. >> >> > > tmp = Tempfile.new([ ''thumb'', ''png'' ].compact.join(".")) >> >> > You can''t use Tempfile to do this. Well, you _can_ but you''ll need to >> > close the file--without unlinking it!--and then move the file created >> > to the new location you want. At that points, you''re better off just >> > giving thumbnails a sequential identifier, or use their hash. Destroy >> > the thumbnail file once you no longer need it. >> >> > > Whenever it creates a temp file, it creates it as such: >> > > thumb.png20101111-989-1pt72my, instead of >> > > thumb20101111-989-1pt72my.png >> >> > > If I try to save this via Active Record, with >> >> > > @video.attachment_thumbnail >> > > File.open("#{File.expand_path(tmp.path)}"), >> >> > > It will save the file in the file system without the extension, which >> > > makes it impossible to read on the browser, unless I explicitly set >> > > the extension. >> >> > > On Nov 12, 3:54 am, Brian Troutwine <br...-MmYI4SXeg2M3tL2svhKZZQ@public.gmane.org> wrote: >> > >> Hi Christian, >> >> > >> Not by the end of the day, no. Each tempfile will be unlinked as soon >> > >> as you close it. Your example code didn''t have the line >> >> > >> > dst.close(unlink_now=true) >> >> > >> in it. You may also use dst.close!() to the same effect. >> >> > >> -- >> > >> Brian >> >> > >> On Thu, Nov 11, 2010 at 2:49 PM, Christian Fazzini >> >> > >> <christian.fazz...-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org> wrote: >> > >> > Hi Brian, >> >> > >> > Just to keep things clear. By the end of the day, /var/folders/uL/ >> > >> > uL0bYOOZEZaJH5E+BmDJVE+++TI/-Tmp-/ <-- temp dir _IS_ supposed to be >> > >> > empty. Is this correct? >> >> > >> > On Nov 12, 3:35 am, Brian Troutwine <br...-MmYI4SXeg2M3tL2svhKZZQ@public.gmane.org> wrote: >> > >> >> When you close the Tempfile, be sure to pass true for unlink_now. >> >> > >> >>http://ruby-doc.org/stdlib/libdoc/tempfile/rdoc/classes/Tempfile.html... >> >> > >> >> On Thu, Nov 11, 2010 at 2:33 PM, Christian Fazzini >> >> > >> >> <christian.fazz...-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org> wrote: >> > >> >> > In video controller, create action. I am using FFMPEG to generate a >> > >> >> > thumbnail of videos that are uploaded. >> >> > >> >> > The tempfile is created as such: >> >> > >> >> > def create >> > >> >> > ...... >> > >> >> > dst = Tempfile.new(basename) >> > >> >> > dst.binmode >> >> > >> >> > system("ffmpeg -itsoffset -4 -i #{file.path} -y -vcodec mjpeg - >> > >> >> > vframes 1 -an -f rawvideo #{File.expand_path(dst.path)}.png") >> > >> >> > .... >> > >> >> > end >> >> > >> >> > As you can see from above, ffmpeg outputs a file to the var dst which >> > >> >> > is an instance of Tempfile. In console, when I do: >> >> > >> >> > ls /var/folders/uL/uL0bYOOZEZaJH5E+BmDJVE+++TI/-Tmp-/ >> >> > >> >> > thumb20101111-989-1gflwhr.png >> > >> >> > thumb20101111-989-1pt72my.png >> > >> >> > thumb20101111-989-kjcsgd.png >> > >> >> > thumb20101111-989-3ocf15.png >> > >> >> > thumb20101111-989-10azwnn.png >> > >> >> > thumb20101111-989-7x11w7.png >> >> > >> >> > I see a bunch of files in the directory. It seems that rails did not >> > >> >> > automatically delete these temp files. Should I manually delete these >> > >> >> > files? >> >> > >> >> > I am worried that, if my temp dir fills up with temp files, it''ll >> > >> >> > eventually take up most of the server space... >> >> > >> >> > Your thoughts on this matter? >> >> > >> >> > -- >> > >> >> > You received this message because you are subscribed to the Google Groups "Ruby on Rails: Talk" group. >> > >> >> > To post to this group, send email to rubyonrails-talk@googlegroups.com. >> > >> >> > To unsubscribe from this group, send email to rubyonrails-talk+unsubscribe-/JYPxA39Uh5TLH3MbocFF+G/Ez6ZCGd0@public.gmane.org >> > >> >> > For more options, visit this group athttp://groups.google.com/group/rubyonrails-talk?hl=en. >> >> > >> > -- >> > >> > You received this message because you are subscribed to the Google Groups "Ruby on Rails: Talk" group. >> > >> > To post to this group, send email to rubyonrails-talk@googlegroups.com. >> > >> > To unsubscribe from this group, send email to rubyonrails-talk+unsubscribe-/JYPxA39Uh5TLH3MbocFF+G/Ez6ZCGd0@public.gmane.org >> > >> > For more options, visit this group athttp://groups.google.com/group/rubyonrails-talk?hl=en. >> >> > > -- >> > > You received this message because you are subscribed to the Google Groups "Ruby on Rails: Talk" group. >> > > To post to this group, send email to rubyonrails-talk@googlegroups.com. >> > > To unsubscribe from this group, send email to rubyonrails-talk+unsubscribe-/JYPxA39Uh5TLH3MbocFF+G/Ez6ZCGd0@public.gmane.org >> > > For more options, visit this group athttp://groups.google.com/group/rubyonrails-talk?hl=en. >> >> > > -- > You received this message because you are subscribed to the Google Groups "Ruby on Rails: Talk" group. > To post to this group, send email to rubyonrails-talk-/JYPxA39Uh5TLH3MbocFF+G/Ez6ZCGd0@public.gmane.org > To unsubscribe from this group, send email to rubyonrails-talk+unsubscribe@googlegroups.com. > For more options, visit this group at http://groups.google.com/group/rubyonrails-talk?hl=en. > >-- You received this message because you are subscribed to the Google Groups "Ruby on Rails: Talk" group. To post to this group, send email to rubyonrails-talk-/JYPxA39Uh5TLH3MbocFF+G/Ez6ZCGd0@public.gmane.org To unsubscribe from this group, send email to rubyonrails-talk+unsubscribe@googlegroups.com. For more options, visit this group at http://groups.google.com/group/rubyonrails-talk?hl=en.
> Would not this conflict if you have multiple users uploading files atthe same time? Yea, thinking along those lines. It would conflict. So if tmp Tempfile.new([ ''thumb'', ''png'' ].compact.join(".")) creates temp files as thumb.png20101111-989-1pt72my, how would I tell Active Record to save it with a .png extension, since it is a png file after all. Remember, @video.attachment_thumbnail File.open(File.expand_path(tmp.path)), saves the file in the file system as thumb.png20101111-989-1pt72my (raw file, no extension) On Nov 12, 4:30 am, Brian Troutwine <br...-MmYI4SXeg2M3tL2svhKZZQ@public.gmane.org> wrote:> On Thu, Nov 11, 2010 at 3:21 PM, Christian Fazzini > > <christian.fazz...-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org> wrote: > > No, the following saves the temp file. > > > @video.attachment_thumbnail > > File.open(File.expand_path(tmp.path)) > > Ah, apologies. > > > However, File.expand_path(tmp.path) saves the file in the file system > > as thumb.png20101111-989-1pt72my > > Ideally, I would like it to save it as thumb20101111-989-1pt72my.png > > Okay, so you''ve got this: > > >>> tmp = Tempfile.new([ ''thumb'', ''png'' ].compact.join(".")) > > The documentation for Tempfile states that .new "creates a temporary > file of mode 0600 in the temporary directory whose name is > basename.pid.n and opens with mode "w+". A Tempfile object works just > like a File object." The computer is doing exactly what you tell it to > do. > > > or, better, just thumb.png > > Would not this conflict if you have multiple users uploading files at > the same time? > > > On Nov 12, 4:12 am, Brian Troutwine <br...-MmYI4SXeg2M3tL2svhKZZQ@public.gmane.org> wrote: > >> I''m confused. You''re creating a tempfile and then keeping a reference > >> to it in your database? > > >> On Thu, Nov 11, 2010 at 3:06 PM, Christian Fazzini > > >> <christian.fazz...-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org> wrote: > >> > Ok that makes sense. Thanks Brian. > > >> > On the same topic... > > >> > How would I create a temp file with .png extension in the end. > > >> > tmp = Tempfile.new([ ''thumb'', ''png'' ].compact.join(".")) > > >> You can''t use Tempfile to do this. Well, you _can_ but you''ll need to > >> close the file--without unlinking it!--and then move the file created > >> to the new location you want. At that points, you''re better off just > >> giving thumbnails a sequential identifier, or use their hash. Destroy > >> the thumbnail file once you no longer need it. > > >> > Whenever it creates a temp file, it creates it as such: > >> > thumb.png20101111-989-1pt72my, instead of > >> > thumb20101111-989-1pt72my.png > > >> > If I try to save this via Active Record, with > > >> > @video.attachment_thumbnail > >> > File.open("#{File.expand_path(tmp.path)}"), > > >> > It will save the file in the file system without the extension, which > >> > makes it impossible to read on the browser, unless I explicitly set > >> > the extension. > > >> > On Nov 12, 3:54 am, Brian Troutwine <br...-MmYI4SXeg2M3tL2svhKZZQ@public.gmane.org> wrote: > >> >> Hi Christian, > > >> >> Not by the end of the day, no. Each tempfile will be unlinked as soon > >> >> as you close it. Your example code didn''t have the line > > >> >> > dst.close(unlink_now=true) > > >> >> in it. You may also use dst.close!() to the same effect. > > >> >> -- > >> >> Brian > > >> >> On Thu, Nov 11, 2010 at 2:49 PM, Christian Fazzini > > >> >> <christian.fazz...-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org> wrote: > >> >> > Hi Brian, > > >> >> > Just to keep things clear. By the end of the day, /var/folders/uL/ > >> >> > uL0bYOOZEZaJH5E+BmDJVE+++TI/-Tmp-/ <-- temp dir _IS_ supposed to be > >> >> > empty. Is this correct? > > >> >> > On Nov 12, 3:35 am, Brian Troutwine <br...-MmYI4SXeg2M3tL2svhKZZQ@public.gmane.org> wrote: > >> >> >> When you close the Tempfile, be sure to pass true for unlink_now. > > >> >> >>http://ruby-doc.org/stdlib/libdoc/tempfile/rdoc/classes/Tempfile.html... > > >> >> >> On Thu, Nov 11, 2010 at 2:33 PM, Christian Fazzini > > >> >> >> <christian.fazz...-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org> wrote: > >> >> >> > In video controller, create action. I am using FFMPEG to generate a > >> >> >> > thumbnail of videos that are uploaded. > > >> >> >> > The tempfile is created as such: > > >> >> >> > def create > >> >> >> > ...... > >> >> >> > dst = Tempfile.new(basename) > >> >> >> > dst.binmode > > >> >> >> > system("ffmpeg -itsoffset -4 -i #{file.path} -y -vcodec mjpeg - > >> >> >> > vframes 1 -an -f rawvideo #{File.expand_path(dst.path)}.png") > >> >> >> > .... > >> >> >> > end > > >> >> >> > As you can see from above, ffmpeg outputs a file to the var dst which > >> >> >> > is an instance of Tempfile. In console, when I do: > > >> >> >> > ls /var/folders/uL/uL0bYOOZEZaJH5E+BmDJVE+++TI/-Tmp-/ > > >> >> >> > thumb20101111-989-1gflwhr.png > >> >> >> > thumb20101111-989-1pt72my.png > >> >> >> > thumb20101111-989-kjcsgd.png > >> >> >> > thumb20101111-989-3ocf15.png > >> >> >> > thumb20101111-989-10azwnn.png > >> >> >> > thumb20101111-989-7x11w7.png > > >> >> >> > I see a bunch of files in the directory. It seems that rails did not > >> >> >> > automatically delete these temp files. Should I manually delete these > >> >> >> > files? > > >> >> >> > I am worried that, if my temp dir fills up with temp files, it''ll > >> >> >> > eventually take up most of the server space... > > >> >> >> > Your thoughts on this matter? > > >> >> >> > -- > >> >> >> > You received this message because you are subscribed to the Google Groups "Ruby on Rails: Talk" group. > >> >> >> > To post to this group, send email to rubyonrails-talk@googlegroups.com. > >> >> >> > To unsubscribe from this group, send email to rubyonrails-talk+unsubscribe-/JYPxA39Uh5TLH3MbocFF+G/Ez6ZCGd0@public.gmane.org > >> >> >> > For more options, visit this group athttp://groups.google.com/group/rubyonrails-talk?hl=en. > > >> >> > -- > >> >> > You received this message because you are subscribed to the Google Groups "Ruby on Rails: Talk" group. > >> >> > To post to this group, send email to rubyonrails-talk@googlegroups.com. > >> >> > To unsubscribe from this group, send email to rubyonrails-talk+unsubscribe-/JYPxA39Uh5TLH3MbocFF+G/Ez6ZCGd0@public.gmane.org > >> >> > For more options, visit this group athttp://groups.google.com/group/rubyonrails-talk?hl=en. > > >> > -- > >> > You received this message because you are subscribed to the Google Groups "Ruby on Rails: Talk" group. > >> > To post to this group, send email to rubyonrails-talk@googlegroups.com. > >> > To unsubscribe from this group, send email to rubyonrails-talk+unsubscribe-/JYPxA39Uh5TLH3MbocFF+G/Ez6ZCGd0@public.gmane.org > >> > For more options, visit this group athttp://groups.google.com/group/rubyonrails-talk?hl=en. > > > -- > > You received this message because you are subscribed to the Google Groups "Ruby on Rails: Talk" group. > > To post to this group, send email to rubyonrails-talk-/JYPxA39Uh5TLH3MbocFF+G/Ez6ZCGd0@public.gmane.org > > To unsubscribe from this group, send email to rubyonrails-talk+unsubscribe-/JYPxA39Uh5TLH3MbocFF+G/Ez6ZCGd0@public.gmane.org > > For more options, visit this group athttp://groups.google.com/group/rubyonrails-talk?hl=en. > >-- You received this message because you are subscribed to the Google Groups "Ruby on Rails: Talk" group. To post to this group, send email to rubyonrails-talk-/JYPxA39Uh5TLH3MbocFF+G/Ez6ZCGd0@public.gmane.org To unsubscribe from this group, send email to rubyonrails-talk+unsubscribe@googlegroups.com. For more options, visit this group at http://groups.google.com/group/rubyonrails-talk?hl=en.
> Yes, but not with Tempfile.There wont be any conflicts?> Hash the video data, store your thumbnail as $HASH.png, keep a reference to this fileCan you give me an example of how I would $HASH a file? How do you mean "keep a reference to this file"? On Nov 12, 4:31 am, Brian Troutwine <br...-MmYI4SXeg2M3tL2svhKZZQ@public.gmane.org> wrote:> Yes, but not with Tempfile. Hash the video data, store your thumbnail > as $HASH.png, keep a reference to this file and be sure to delete it > when the user performs such actions as make the thumbnail no longer > necessary. > > On Thu, Nov 11, 2010 at 3:29 PM, Christian Fazzini > > <christian.fazz...-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org> wrote: > > Basically I need to create a new tempfile with a png extension. Is > > this possible? > > > On Nov 12, 4:21 am, Christian Fazzini <christian.fazz...-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org> > > wrote: > >> No, the following saves the temp file. > > >> @video.attachment_thumbnail > >> File.open(File.expand_path(tmp.path)) > > >> However, File.expand_path(tmp.path) saves the file in the file system > >> as thumb.png20101111-989-1pt72my > > >> Ideally, I would like it to save it as thumb20101111-989-1pt72my.png > >> or, better, just thumb.png > > >> On Nov 12, 4:12 am, Brian Troutwine <br...-MmYI4SXeg2M3tL2svhKZZQ@public.gmane.org> wrote: > > >> > I''m confused. You''re creating a tempfile and then keeping a reference > >> > to it in your database? > > >> > On Thu, Nov 11, 2010 at 3:06 PM, Christian Fazzini > > >> > <christian.fazz...-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org> wrote: > >> > > Ok that makes sense. Thanks Brian. > > >> > > On the same topic... > > >> > > How would I create a temp file with .png extension in the end. > > >> > > tmp = Tempfile.new([ ''thumb'', ''png'' ].compact.join(".")) > > >> > You can''t use Tempfile to do this. Well, you _can_ but you''ll need to > >> > close the file--without unlinking it!--and then move the file created > >> > to the new location you want. At that points, you''re better off just > >> > giving thumbnails a sequential identifier, or use their hash. Destroy > >> > the thumbnail file once you no longer need it. > > >> > > Whenever it creates a temp file, it creates it as such: > >> > > thumb.png20101111-989-1pt72my, instead of > >> > > thumb20101111-989-1pt72my.png > > >> > > If I try to save this via Active Record, with > > >> > > @video.attachment_thumbnail > >> > > File.open("#{File.expand_path(tmp.path)}"), > > >> > > It will save the file in the file system without the extension, which > >> > > makes it impossible to read on the browser, unless I explicitly set > >> > > the extension. > > >> > > On Nov 12, 3:54 am, Brian Troutwine <br...-MmYI4SXeg2M3tL2svhKZZQ@public.gmane.org> wrote: > >> > >> Hi Christian, > > >> > >> Not by the end of the day, no. Each tempfile will be unlinked as soon > >> > >> as you close it. Your example code didn''t have the line > > >> > >> > dst.close(unlink_now=true) > > >> > >> in it. You may also use dst.close!() to the same effect. > > >> > >> -- > >> > >> Brian > > >> > >> On Thu, Nov 11, 2010 at 2:49 PM, Christian Fazzini > > >> > >> <christian.fazz...-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org> wrote: > >> > >> > Hi Brian, > > >> > >> > Just to keep things clear. By the end of the day, /var/folders/uL/ > >> > >> > uL0bYOOZEZaJH5E+BmDJVE+++TI/-Tmp-/ <-- temp dir _IS_ supposed to be > >> > >> > empty. Is this correct? > > >> > >> > On Nov 12, 3:35 am, Brian Troutwine <br...-MmYI4SXeg2M3tL2svhKZZQ@public.gmane.org> wrote: > >> > >> >> When you close the Tempfile, be sure to pass true for unlink_now. > > >> > >> >>http://ruby-doc.org/stdlib/libdoc/tempfile/rdoc/classes/Tempfile.html... > > >> > >> >> On Thu, Nov 11, 2010 at 2:33 PM, Christian Fazzini > > >> > >> >> <christian.fazz...-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org> wrote: > >> > >> >> > In video controller, create action. I am using FFMPEG to generate a > >> > >> >> > thumbnail of videos that are uploaded. > > >> > >> >> > The tempfile is created as such: > > >> > >> >> > def create > >> > >> >> > ...... > >> > >> >> > dst = Tempfile.new(basename) > >> > >> >> > dst.binmode > > >> > >> >> > system("ffmpeg -itsoffset -4 -i #{file.path} -y -vcodec mjpeg - > >> > >> >> > vframes 1 -an -f rawvideo #{File.expand_path(dst.path)}.png") > >> > >> >> > .... > >> > >> >> > end > > >> > >> >> > As you can see from above, ffmpeg outputs a file to the var dst which > >> > >> >> > is an instance of Tempfile. In console, when I do: > > >> > >> >> > ls /var/folders/uL/uL0bYOOZEZaJH5E+BmDJVE+++TI/-Tmp-/ > > >> > >> >> > thumb20101111-989-1gflwhr.png > >> > >> >> > thumb20101111-989-1pt72my.png > >> > >> >> > thumb20101111-989-kjcsgd.png > >> > >> >> > thumb20101111-989-3ocf15.png > >> > >> >> > thumb20101111-989-10azwnn.png > >> > >> >> > thumb20101111-989-7x11w7.png > > >> > >> >> > I see a bunch of files in the directory. It seems that rails did not > >> > >> >> > automatically delete these temp files. Should I manually delete these > >> > >> >> > files? > > >> > >> >> > I am worried that, if my temp dir fills up with temp files, it''ll > >> > >> >> > eventually take up most of the server space... > > >> > >> >> > Your thoughts on this matter? > > >> > >> >> > -- > >> > >> >> > You received this message because you are subscribed to the Google Groups "Ruby on Rails: Talk" group. > >> > >> >> > To post to this group, send email to rubyonrails-talk@googlegroups.com. > >> > >> >> > To unsubscribe from this group, send email to rubyonrails-talk+unsubscribe-/JYPxA39Uh5TLH3MbocFF+G/Ez6ZCGd0@public.gmane.org > >> > >> >> > For more options, visit this group athttp://groups.google.com/group/rubyonrails-talk?hl=en. > > >> > >> > -- > >> > >> > You received this message because you are subscribed to the Google Groups "Ruby on Rails: Talk" group. > >> > >> > To post to this group, send email to rubyonrails-talk@googlegroups.com. > >> > >> > To unsubscribe from this group, send email to rubyonrails-talk+unsubscribe-/JYPxA39Uh5TLH3MbocFF+G/Ez6ZCGd0@public.gmane.org > >> > >> > For more options, visit this group athttp://groups.google.com/group/rubyonrails-talk?hl=en. > > >> > > -- > >> > > You received this message because you are subscribed to the Google Groups "Ruby on Rails: Talk" group. > >> > > To post to this group, send email to rubyonrails-talk@googlegroups.com. > >> > > To unsubscribe from this group, send email to rubyonrails-talk+unsubscribe-/JYPxA39Uh5TLH3MbocFF+G/Ez6ZCGd0@public.gmane.org > >> > > For more options, visit this group athttp://groups.google.com/group/rubyonrails-talk?hl=en. > > > -- > > You received this message because you are subscribed to the Google Groups "Ruby on Rails: Talk" group. > > To post to this group, send email to rubyonrails-talk-/JYPxA39Uh5TLH3MbocFF+G/Ez6ZCGd0@public.gmane.org > > To unsubscribe from this group, send email to rubyonrails-talk+unsubscribe-/JYPxA39Uh5TLH3MbocFF+G/Ez6ZCGd0@public.gmane.org > > For more options, visit this group athttp://groups.google.com/group/rubyonrails-talk?hl=en. > >-- You received this message because you are subscribed to the Google Groups "Ruby on Rails: Talk" group. To post to this group, send email to rubyonrails-talk-/JYPxA39Uh5TLH3MbocFF+G/Ez6ZCGd0@public.gmane.org To unsubscribe from this group, send email to rubyonrails-talk+unsubscribe@googlegroups.com. For more options, visit this group at http://groups.google.com/group/rubyonrails-talk?hl=en.