# File lib/youtube_g/request/video_upload.rb, line 39
      def upload data, opts = {}
        data = data.respond_to?(:read) ? data.read : data
        @opts = { :mime_type => 'video/mp4',
                  :filename => Digest::MD5.hexdigest(data),
                  :title => '',
                  :description => '',
                  :category => '',
                  :keywords => [] }.merge(opts)

        uploadBody = generate_upload_body(boundary, video_xml, data)

        uploadHeader = {
          "Authorization"  => "GoogleLogin auth=#{auth_token}",
          "X-GData-Client" => "#{@client_id}",
          "X-GData-Key"    => "key=#{@dev_key}",
          "Slug"           => "#{@opts[:filename]}",
          "Content-Type"   => "multipart/related; boundary=#{boundary}",
          "Content-Length" => "#{uploadBody.length}"
        }

        Net::HTTP.start(base_url) do |upload|
          response = upload.post('/feeds/api/users/' << @user << '/uploads', uploadBody, uploadHeader)
          if response.code.to_i == 403
            raise AuthenticationError, response.body[/<TITLE>(.+)<\/TITLE>/, 1]
          elsif response.code.to_i != 201
            upload_error = ''
            xml = REXML::Document.new(response.body)
            errors = xml.elements["//errors"]
            errors.each do |error|
              location = error.elements["location"].text[/media:group\/media:(.*)\/text\(\)/,1]
              code = error.elements["code"].text
              upload_error << sprintf("%s: %s\r\n", location, code)
            end
            raise UploadError, upload_error
          end
          xml = REXML::Document.new(response.body)
          return xml.elements["//id"].text[/videos\/(.+)/, 1]
        end

      end