@param [String] name The name of the entity. @param [read] io The input object to read from. @param [String] image_type Media image type. One of: iso, floppy. @return [Media]
# File lib/fog/vcloud_director/models/compute/medias.rb, line 16 def create(name, io, image_type='iso') requires :vdc response = service.post_upload_media(vdc.id, name, image_type, io.size) service.add_id_from_href!(response.body) media = new(response.body) # Perhaps this would be better implemented as media#upload. file = response.body[:Files][:File].first file[:Link] = [file[:Link]] if file[:Link].is_a?(Hash) link = file[:Link].find {|l| l[:rel] == 'upload:default'} headers = { 'Content-Length' => io.size, 'Content-Type' => 'application/octet-stream', 'x-vcloud-authorization' => service.vcloud_token } chunker = lambda do # to_s will convert the nil received after everything is read to # the final empty chunk. io.read(Excon.defaults[:chunk_size]).to_s end Excon.put( link[:href], :expects => 200, :headers => headers, :request_block => chunker) service.process_task(response.body[:Tasks][:Task]) media.reload media end