Coder Social home page Coder Social logo

Generating a thumbnail output about dropbox_api HOT 4 CLOSED

jesus avatar jesus commented on May 27, 2024
Generating a thumbnail output

from dropbox_api.

Comments (4)

Jesus avatar Jesus commented on May 27, 2024 1

This was undocumented. I've updated the docs now.

Here's an example of how you can save a thumbnail:

client = DropboxApi::Client.new

File.open("thumbnail.png", "w") do |file|
  client.get_thumbnail "/dropbox_image.png" do |thumbnail_content|
    file.write thumbnail_content
  end
end

Please re-open if anything is still unclear.

from dropbox_api.

mocerinoj avatar mocerinoj commented on May 27, 2024

Just to clarify, get_thumbnail seems to be returning DropboxApi::Metadata::File which wouldn't include the thumbnail

from dropbox_api.

elduglas avatar elduglas commented on May 27, 2024

Hi Jesús.

I've a similar problem for display a thumbnail.

ApplicationController

  before_action :authenticator, :dropbox_client

  CLIENT_ID = "XXXXXXX"
  CLIENT_SECRET = "YYYYYY"
  CODE = 'ZZZZZZZ'

private
  def authenticator
    DropboxApi::Authenticator.new(CLIENT_ID, CLIENT_SECRET)
  end

  def dropbox_client
    @dropbox_client ||= DropboxApi::Client.new(CODE)
  end

DropboxController.

 def list
    files = dropbox_client.list_folder "/#{params[:folder_code]}"
    @files = files.entries
  end

ApplicationHelper

 def show_image(image)
    File.open("thumbnail.png", "w") do |file|
      @dropbox_client.get_thumbnail image.path_lower do |thumbnail_content|
        file.write thumbnail_content
      end
    end
  end

List.html.erb

<%= show_image(file) %>

Error.

"\xFF" from ASCII-8BIT to UTF-8

I changed File.open("thumbnail.png", "w") do |file| to File.open("thumbnail.png", "wb") do |file|
and as result I had #DropboxApi::Metadata::File:0x00007f834900f770

How to preview the thumbnail? image_tag, img_src?

Thanks so much. 👍

Gracias.

http://www.xuuso.com/dropbox_api/DropboxApi/Client.html

from dropbox_api.

Jesus avatar Jesus commented on May 27, 2024

Looks like you're trying to download the file to your server on every browser request.

It would make more sense to download the thumbnail to your server once, then serving it just like any other asset.

Anyway, the mistake in your example was that you're failing to generate the image tag, you're embedding the bytes of the image as part of the HTML document. Instead, your view you should have something like:

<%= image_tag("/path/to/downloaded/file/thumbnail.png") %>

from dropbox_api.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.