问题描述:

I have a problem trying to update a Google document containing an image. In the first revision, the image will load as expected. But after updating it with the same HTML code I keep getting a spinner instead of the image.

I am using the Ruby gem created by Google (https://github.com/google/google-api-ruby-client).

Here is my test code:

# Setting up the client instance

require "google/api_client"

require "tempfile"

client = Google::APIClient.new

client.authorization.client_id = "<CLIENTID>"

client.authorization.client_secret = "<CLIENTSECRET>"

client.authorization.redirect_uri = "<REDIRECTURI>"

client.authorization.scope = "https://www.googleapis.com/auth/drive"

client.authorization.access_token = "<ACCESSTOKEN>"

client.authorization.refresh_token = "<REFRESHTOKEN>"

drive = client.discovered_api("drive", "v2")

# Creating the document (IMAGE DISPLAYED CORRECTLY)

file = drive.files.insert.request_schema.new({"title" => "Test document", "mimeType" => "text/html"})

temp = Tempfile.new "temp.html"

temp.write "<h1>Testing!</h1><p>Lorem ipsum.</p><img width='400px' src='http://www.digitaleconomics.nl/wp-content/uploads/2013/04/see-how-your-google-results-measure-up-with-google-grader-video-6b8bbb4b41.jpg'>"

temp.rewind

media = Google::APIClient::UploadIO.new(temp, "text/html")

result = client.execute(:api_method => drive.files.insert, :body_object => file, :media => media, :parameters => {"uploadType" => "multipart", "convert" => true})

temp.close

# Updating the document (GETTING SPINNER INSTEAD OF IMAGE)

file = client.execute(:api_method => drive.files.get, :parameters => {"fileId" => result.data.to_hash["id"]}).data

file.title = "Updated test document"

temp = Tempfile.new "temp.html"

temp.write "<h1>Testing!</h1><p>Lorem ipsum.</p><img width='400px' src='http://www.digitaleconomics.nl/wp-content/uploads/2013/04/see-how-your-google-results-measure-up-with-google-grader-video-6b8bbb4b41.jpg'>"

temp.rewind

media = Google::APIClient::UploadIO.new(temp, "text/html")

result = client.execute(:api_method => drive.files.update, :body_object => file, :media => media, :parameters => {"uploadType" => "multipart", "convert" => true, "fileId" => result.data.to_hash["id"], "newRevision" => false})

temp.close

Also, setting newRevision to false does not prevent a new revision from being created.

Can anyone help me out?

相关阅读:
Top