lib/ruby-box/folder.rb in ruby-box-1.9.2 vs lib/ruby-box/folder.rb in ruby-box-1.9.3
- old
+ new
@@ -11,18 +11,23 @@
def folders(name=nil, item_limit=100, offset=0, fields=nil)
items_by_type(RubyBox::Folder, name, item_limit, offset, fields)
end
- def upload_file(filename, data)
+ def upload_file(filename, data, overwrite=true)
file = RubyBox::File.new(@session, {
'name' => filename,
'parent' => RubyBox::User.new(@session, {'id' => id})
})
begin
resp = file.upload_content(data) #write a new file. If there is a conflict, update the conflicted file.
rescue RubyBox::ItemNameInUse => e
+
+ # if overwrite flag is false, simply raise exception.
+ raise e unless overwrite
+
+ # otherwise let's attempt to overwrite the file.
data.rewind
# The Box API occasionally does not return
# context info for an ItemNameInUse exception.
# This is a workaround around:
\ No newline at end of file