Method: Paperclip::Storage::S3#flush_writes
- Defined in:
- lib/paperclip/storage/s3.rb
#flush_writes ⇒ Object
:nodoc:
351 352 353 354 355 356 357 358 359 360 361 362 363 364 365 366 367 368 369 370 371 372 373 374 375 376 377 378 379 380 381 382 383 384 385 386 387 388 389 390 391 392 393 394 395 396 397 398 399 |
# File 'lib/paperclip/storage/s3.rb', line 351 def flush_writes #:nodoc: @queued_for_write.each do |style, file| retries = 0 begin log("saving #{path(style)}") = { :content_type => file.content_type, :acl => (style) } # add storage class for this style if defined storage_class = s3_storage_class(style) .merge!(:storage_class => storage_class) if storage_class if @s3_server_side_encryption [:server_side_encryption] = @s3_server_side_encryption end = styles[style] if merge_s3_headers( [:s3_headers], @s3_headers, ) if [:s3_headers] .merge!([:s3_metadata]) if [:s3_metadata] end [:metadata] = unless .empty? .merge!(@s3_headers) s3_object(style).upload_file(file.path, ) rescue ::Aws::S3::Errors::NoSuchBucket create_bucket retry rescue ::Aws::S3::Errors::SlowDown retries += 1 if retries <= 5 sleep((2 ** retries) * 0.5) retry else raise end ensure file.rewind end end after_flush_writes # allows attachment to clean up temp files @queued_for_write = {} end |