Class: DropboxApi::Endpoints::Files::GetThumbnail

Inherits:
ContentDownload show all
Includes:
OptionsValidator
Defined in:
lib/dropbox_api/endpoints/files/get_thumbnail.rb

Constant Summary collapse

Method =
:post
Path =
'/2/files/get_thumbnail'
ResultType =
DropboxApi::Metadata::File
ErrorType =
DropboxApi::Errors::PreviewError

Instance Method Summary collapse

Methods included from OptionsValidator

#validate_options

Methods inherited from ContentDownload

#build_connection, #build_request, #perform_request

Methods inherited from Base

add_endpoint, #initialize

Constructor Details

This class inherits a constructor from DropboxApi::Endpoints::Base

Instance Method Details

#get_thumbnail(path, options = {}, &block) ⇒ Object

Get a thumbnail for an image.

This method currently supports files with the following file extensions: jpg, jpeg, png, tiff, tif, gif and bmp. Photos that are larger than 20MB in size won't be converted to a thumbnail.

Examples:

# Save thumbnail to a local file
client = DropboxApi::Client.new
file = File.open("thumbnail.png", "w")
client.get_thumbnail "/dropbox_image.png" do |thumbnail_content|
  file.write thumbnail_content
end
file.close
# Save thumbnail to a local file with .jpg format
client = DropboxApi::Client.new
file = File.open("thumbnail.jpg", "w")
client.get_thumbnail("/dropbox_image.png", :format => :jpeg) do |thumbnail_content|
  file.write thumbnail_content
end
file.close
# Upload thumbnail to Amazon S3 (assuming you're using their SDK)
s3_object = AWS::S3.new.s3.buckets['my-bucket'].objects['key']
#=> <AWS::S3::S3Object ...>
client = DropboxApi::Client.new
client.get_thumbnail "/dropbox_image.png" do |thumbnail_content|
  s3_object.write thumbnail_content
end

Parameters:

  • path (String)

    The path to the image file you want to thumbnail.

Options Hash (options):

  • format (:jpeg, :png)

    The format for the thumbnail image, :jpeg (default) or :png. For images that are photos, :jpeg should be preferred, while png is better for screenshots and digital arts. The default is :jpeg.

  • size (:w32h32, :w64h64, :w128h128, :w640h480, :w1024h768)

    The size for the thumbnail image. The default is :w64h64.



48
49
50
51
52
53
54
55
56
# File 'lib/dropbox_api/endpoints/files/get_thumbnail.rb', line 48

add_endpoint :get_thumbnail do |path, options = {}, &block|
  validate_options([:format, :size], options)
  options[:format] ||= :jpeg
  options[:size] ||= :w64h64

  perform_request(options.merge({
    path: path
  }), &block)
end