This is such a noobie question.
I have a file, http:// ... /One-minute-commercial-027.flv (I can't enter the name because the email gets rejected with a 5.7.1 as spam, apparently.
I want to do two simple things:
1) I want to get the file size. Please note that File.size() does not seem to work for me for a web-based file but does work for a local file.
C:\Users\Ralph>irb
irb(main):001:0> File.size('c:/RailsInstaller/Sites/ultradedup002/app/views/usage/VideoTutorials.html.haml')
=> 32406
irb(main):002:0> File.size('http:// ... /One-minute-commercial-027.flv')
Errno::EINVAL: Invalid argument - http:// something /One-minute-commercial-027.flv
from (irb):2:in `size'
from (irb):2
from C:/RailsInstaller/Ruby1.9.2/bin/irb:12:in `<main>'
irb(main):003:0>
2) I want to read a few hundred bytes from the beginning of the file so as to pick up the flv's time duration.
Are there Ruby facilities to do this?
Ralph Shnelvar
You should probably make a HEAD request and parse Content-Length header
curl --head '<Your URL>' | grep 'Content-Length'
http:// ... /One-minute-commercial-027.flv'
···
On 03/01/12 6:56 PM, Ralph Shnelvar wrote:
This is such a noobie question.
I have a file, http:// ... /One-minute-commercial-027.flv (I can't enter the name because the email gets rejected with a 5.7.1 as spam, apparently.
I want to do two simple things:
1) I want to get the file size. Please note that File.size() does not seem to work for me for a web-based file but does work for a local file.
C:\Users\Ralph>irb
irb(main):001:0> File.size('c:/RailsInstaller/Sites/ultradedup002/app/views/usage/VideoTutorials.html.haml')
=> 32406
irb(main):002:0> File.size('http:// ... /One-minute-commercial-027.flv')
Errno::EINVAL: Invalid argument - http:// something /One-minute-commercial-027.flv
from (irb):2:in `size'
from (irb):2
from C:/RailsInstaller/Ruby1.9.2/bin/irb:12:in `<main>'
irb(main):003:0>
2) I want to read a few hundred bytes from the beginning of the file so as to pick up the flv's time duration.
Are there Ruby facilities to do this?
Ralph Shnelvar
Tuesday, January 3, 2012, 6:39:07 AM, you wrote:
You should probably make a HEAD request and parse Content-Length header
curl --head '<Your URL>' | grep 'Content-Length'
http:// ... /One-minute-commercial-027.flv'
Could you beef up the example/explanation a bit, please.
Also, what about reading a few hundred bytes from the flv?
···
On 03/01/12 6:56 PM, Ralph Shnelvar wrote:
This is such a noobie question.
I have a file, http:// ... /One-minute-commercial-027.flv (I can't enter the name because the email gets rejected with a 5.7.1 as spam, apparently.
I want to do two simple things:
1) I want to get the file size. Please note that File.size() does not seem to work for me for a web-based file but does work for a local file.
C:\Users\Ralph>irb
irb(main):001:0> File.size('c:/RailsInstaller/Sites/ultradedup002/app/views/usage/VideoTutorials.html.haml')
=> 32406
irb(main):002:0> File.size('http:// ... /One-minute-commercial-027.flv')
Errno::EINVAL: Invalid argument - http:// something /One-minute-commercial-027.flv
from (irb):2:in `size'
from (irb):2
from C:/RailsInstaller/Ruby1.9.2/bin/irb:12:in `<main>'
irb(main):003:0>
2) I want to read a few hundred bytes from the beginning of the file so as to pick up the flv's time duration.
Are there Ruby facilities to do this?
Ralph Shnelvar
--
Best regards,
Ralph mailto:ralphs@dos32.com
using net/http -- something like
ruby-1.9.2-p290 :035 > uri = URI('http://localhost/'\)
=> #<URI::HTTP:0x00000101861f80 URL:http://localhost/>
ruby-1.9.2-p290 :036 > req = Net::HTTP::Get.new(uri.request_uri)
=> #<Net::HTTP::Get GET>
ruby-1.9.2-p290 :037 > req['Range'] = 'bytes=0-99'
=> "bytes=0-99"
ruby-1.9.2-p290 :038 > Net::HTTP.start(uri.host, uri.port) {|http|
http.request(req) }.body
=> "<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN"\n
"http://www.w3.org/TR/xhtml1/D"
ruby-1.9.2-p290 :039 >
The above *does* assume that your web server supports the Range
header, so YMMV.
···
On Tue, Jan 3, 2012 at 6:03 AM, Ralph Shnelvar <ralphs@dos32.com> wrote:
Also, what about reading a few hundred bytes from the flv?
--
Hassan Schroeder ------------------------ hassan.schroeder@gmail.com
twitter: @hassan