【问题标题】:how to upload file to google drive using sdk in uploadtype=media如何在uploadtype = media中使用sdk将文件上传到谷歌驱动器
【发布时间】:2013-09-12 01:01:43
【问题描述】:

我正在尝试将文件上传到谷歌驱动器。 作为

token_res = Rho::AsyncHttp.post(
:url => "https://www.googleapis.com/upload/drive/v2/files?uploadType=media", :headers => {'Content-Type'=> 'image/jpg','Content-Transfer-Encoding'=> 'base64', 'Authorization'=> tokn_final ,'X-JavaScript-User-Agent'=>' Google API 资源管理器'}, :body => image_path )

上传了一个文件,如果我在正文中给出字符串:body=> 'some string...' 但是如果我在正文中给出 image_path,它不会上传文件,它只会将文件的路径作为字符串上传。

我不知道如何上传文件,请帮我上传。

【问题讨论】:

    标签: javascript google-drive-api rhomobile


    【解决方案1】:

    您需要将图像作为二进制编码放入正文,而不是图像的路径。如果您使用的是 Ruby 客户端库,那就更简单了。

    drive = client.discovered_api('drive', 'v2')
    media = Google::APIClient::UploadIO.new(file_name, mime_type)
    result = client.execute(
      :api_method => drive.files.insert,
      :media => media,
      :parameters => {'uploadType' => 'media'}
    )
    

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 2018-11-10
      • 1970-01-01
      • 1970-01-01
      • 2013-04-20
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多