Error creating folder in google drive through ruby -
i'm having trouble creating folder in google drive using google-drive-api library in ruby. can log in, list folders, add file root folder. have folder called 'applications' under root folder. listing files show id folder, lets call "0bwivxebt'. in controller init google drive connection (as i'm able list files) , call create_parent('test') method in google_drive_connection.rb:
def create_folder (title) file = @drive.files.insert.request_schema.new({ 'title' => title, 'description' => title, 'mimetype' => 'application/vnd.google-apps.folder' }) file.parents = [{"id" => '0bwivxebt'}] # 0bwivxebt id applications folder media = google::apiclient::uploadio.new(title, 'application/vnd.google-apps.folder') result = @client.execute( :api_method => @drive.files.insert, :body_object => file, :media => media, :parameters => { 'uploadtype' => 'multipart', #'convert' => false, 'alt' => 'json'}) if result.status == 200 return result.data else puts "an error occurred: #{result.data['error']['message']}" return nil end end
for saw in other post insert folder file insert (which works fine in ahother method in rb file), title no extension, , mimetype 'application/vnd.google-apps.folder'
error: no such file or directory - test
probably minor issue, can't seem find it!
thanks pointer / provided.
edit found problem, interested in solution, folders need send metadata in request, no need media part, needs body (metadata) information, 'create_folder' method results in:
def create_folder (title) file = @drive.files.insert.request_schema.new({ 'title' => title, 'description' => title, 'mimetype' => 'application/vnd.google-apps.folder' }) file.parents = [{"id" => '0bwivxebt'}] # 0bwivxebt id applications folder result = @client.execute( :api_method => @drive.files.insert, :body_object => file) if result.status == 200 return result.data else puts "an error occurred: #{result.data['error']['message']}" return nil end end
found answer question, added edit in original question solution. in few words, folder add body part, not media part in request. folders, metadata required.
Comments
Post a Comment