Well you don't want to buffer the whole file into memory (think about when
you are uploading a 800MB YouTube file.) So what happens here is the
request's body property is set to a File object, like you noticed, but then
in default_service.rb:

case request.body
when String
  req.body = request.body
when Hash
  req.set_form_data(request.body)
when File
  req.body_stream = request.body
  request.chunked = true
when GData::HTTP::MimeBody
  req.body_stream = request.body
  request.chunked = true
else
  req.body = request.body.to_s
end

Notice that when the body is a File object, we set the body_stream to be the
file object and tell it to use chunked encoding. This causes Net::HTTP to
read from that file object when sending its request.

So I don't think this is the bug, though it could be there is some bug with
how Net::HTTP is doing the chunked encoding that is broken for 1.8.7.

Cheers,
-Jeff



On Wed, May 6, 2009 at 1:43 PM, Leonardo Borges Barbosa <
[email protected]> wrote:

> Jeff, I believe I found another bug. After I sent you my last email I went
> digging in gdata's source code and found the reason for that specific
> exception.
>
> In lib/gdata/client/base.rb, method make_file_request, the line 64 reads
> like this:
>           response = self.make_request(method, url, file)
>
> This causes this request to be sent:
> <GData::HTTP::Request:0x15ad8a8 @url="
> http://picasaweb.google.com/data/feed/api/user/leonardoborges.rj/albumid/5332810669099119713";,
> @body=#<File:DSC03698.JPG>, @headers={"Slug"=>"DSC03698.JPG",
> "Authorization"=>"GoogleLogin
> auth=DQAAAHcAAABin-tFCqAN96yAfnDUqaBFBeU4g3r3C4Cogi9gajT9eV9LBenYIy3bpyj-SBy6xro4E8htvuMehmjfuQw8KpjVXS0fYDOjiW1k1bv1aAVJE_BOO5DvOGvtvBGEV1Anu610EL9ITwbyAxBIRrt2DGlV_XpBk8dRR8f0JPJctrWYNQ",
> "Content-Type"=>"image/jpeg",
> "User-Agent"=>"GoogleDataRubyUtil-AnonymousApp", "Content-Length"=>588,
> "GData-Version"=>"1"}, @method=:post>
>
> If you look at the body, it contains the default representation of the
> method inspect from the object File, instead of the actual data.
> Changing the line to:
>           response = self.make_request(method, url, file.read)
> does the trick. I've just successfully upload the picture.
>
> If this is really a bug, I can fill in a patch request. Just let me know.
>
> Tks,
> Leonardo Borges
> www.leonardoborges.com
>
>
>
> On Wed, May 6, 2009 at 9:53 PM, Jeff Fisher <[email protected]>wrote:
>
>> Well, it seems you have found one bug - the exception code which was
>> recently revamped in a patch missed a case. This is fixed now:
>>
>> http://code.google.com/p/gdata-ruby-util/source/detail?r=29
>>
>> But I'm still unable to reproduce your error. I uploaded the file you gave
>> successfully. I'm using the stock Ruby with Leopard which seems to be ruby
>> 1.8.6 (2008-03-03 patchlevel 114) [universal-darwin9.0]
>>
>> Can you dig into Wireshark and see what it is sending in the request?
>>
>> Cheers,
>> -Jeff
>>
>>
>> On Wed, May 6, 2009 at 11:32 AM, Leonardo Borges Barbosa <
>> [email protected]> wrote:
>>
>>> Hi Jeff,
>>>
>>> I was trying that for a project at work so I just got home and tried the
>>> same code with the attached image - which is bigger - and I'm getting this:
>>>
>>> NoMethodError: undefined method `status_code' for "Not a valid
>>> image.":String
>>>     from
>>> /opt/local/lib/ruby/gems/1.8/gems/gdata-1.1.0/lib/gdata/client.rb:50:in
>>> `initialize'
>>>     from
>>> /opt/local/lib/ruby/gems/1.8/gems/gdata-1.1.0/lib/gdata/client/base.rb:89:in
>>> `exception'
>>>     from
>>> /opt/local/lib/ruby/gems/1.8/gems/gdata-1.1.0/lib/gdata/client/base.rb:89:in
>>> `raise'
>>>     from
>>> /opt/local/lib/ruby/gems/1.8/gems/gdata-1.1.0/lib/gdata/client/base.rb:89:in
>>> `make_request'
>>>     from
>>> /opt/local/lib/ruby/gems/1.8/gems/gdata-1.1.0/lib/gdata/client/base.rb:64:in
>>> `make_file_request'
>>>     from
>>> /opt/local/lib/ruby/gems/1.8/gems/gdata-1.1.0/lib/gdata/client/base.rb:123:in
>>> `post_file'
>>>     from ./picasa.rb:54:in `up_photo'
>>>     from (irb):7
>>>     from /opt/local/lib/ruby/site_ruby/1.8/rubygems/exceptions.rb:75
>>>
>>> As a side node, the attached image is in one of my albums as well, so
>>> it's a valid image.
>>>
>>> Thanks
>>> PS: This is my ruby version:
>>> ruby 1.8.7 (2008-08-11 patchlevel 72) [i686-darwin9]
>>>
>>>
>>> On Wed, May 6, 2009 at 7:08 PM, Jeff Fisher <[email protected]>wrote:
>>>
>>>> Very strange. I just verified I could upload a large image (since the
>>>> test image is minuscule) and it worked with a 5100×3338 pixel image. Can 
>>>> you
>>>> e-mail me an image that is failing for you? Also it might help to know what
>>>> version of Ruby you are running.
>>>>
>>>> Cheers,
>>>> -Jeff
>>>>
>>>>
>>>> On Wed, May 6, 2009 at 8:14 AM, Leonardo Borges <
>>>> [email protected]> wrote:
>>>>
>>>>>
>>>>> Hey guys, I've searched the knowledge base about this issue but didn't
>>>>> find a suitable answer yet.
>>>>>
>>>>> Using ruby with the gdata gem, I'm able to list all albums in my
>>>>> account, get information like title, number of photos and etc.
>>>>>
>>>>> I am also able to create new albums perfectly but when I try to upload
>>>>> any picture, this is how my album looks like:
>>>>> http://picasaweb.google.com/leonardoborges.rj/TestAlbum
>>>>>
>>>>> As you can see, seems like the data was not properly transmitted over
>>>>> the web.
>>>>>
>>>>> This is how my upload code looks like: - pretty much taken from the
>>>>> test case
>>>>> def up_photo(test_image)
>>>>>    mime_type = 'image/jpeg'
>>>>>
>>>>>    response = @@client.post_file(@@atom_url,
>>>>>      test_image, mime_type).to_xml
>>>>>
>>>>>    puts response
>>>>> end
>>>>>
>>>>> And in the following link you can check the contents of the response I
>>>>> get after uploading the picture:
>>>>> http://pastie.org/470038
>>>>>
>>>>> Am I missing something?
>>>>>
>>>>>
>>>>> PS: The image is below the 20MB limit.
>>>>>
>>>>>
>>>>>
>>>>>
>>>>
>>>>
>>>>
>>>
>>>
>>>
>>
>>
>>
>
> >
>

--~--~---------~--~----~------------~-------~--~----~
You received this message because you are subscribed to the Google Groups 
"Google Picasa Web Albums API" group.
To post to this group, send email to [email protected]
To unsubscribe from this group, send email to 
[email protected]
For more options, visit this group at 
http://groups.google.com/group/Google-Picasa-Data-API?hl=en
-~----------~----~----~----~------~----~------~--~---

Reply via email to