首页 > 解决方案 > 如何在不保存本地的情况下将数据上传到谷歌存储

问题描述

这段代码对我很有效:

GCloudex.CloudStorage.Client.put_object_content("my-bucket", "my_file_name", "heloo")

我现在正在尝试使用 swagger 库google_api_storage这也是我尝试过的:

  @spec upload_file(bucket_id, file_path, name) :: {:ok, media_link} | {:error, error_message}
  def upload_file(bucket_id, file_path, name) do
    # Make the API request.
    res = GoogleApi.Storage.V1.Api.Objects.storage_objects_insert_simple(
                    Connection.get(), bucket_id, "multipart",
                    %{name: Path.basename(name)}, file_path)
    case res do
      {:ok, %GoogleApi.Storage.V1.Model.Object{mediaLink: media_link}} -> {:ok, media_link}
      {:error, %Tesla.Env{body: body}} -> {:error, body}
      _ -> {:error, "unkonw error"}
    end

  end

我想上传而不在本地保存,我会使用什么功能以及如何使用?
storage_objects_insert - 我看不到可以在请求中插入内容正文的位置?


一般来说,api中是否有任何参考将数据上传到谷歌文档中的存储?

标签: elixirgoogle-cloud-storage

解决方案


使用 Google Cloud Storage API,您可以直接在 POST 请求的正文中提供文件数据。您可以在此处找到 Cloud Storage 对象插入 API 参考:


推荐阅读