elixir - 如何在不保存本地的情况下将数据上传到谷歌存储
问题描述
这段代码对我很有效:
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中是否有任何参考将数据上传到谷歌文档中的存储?
解决方案
使用 Google Cloud Storage API,您可以直接在 POST 请求的正文中提供文件数据。您可以在此处找到 Cloud Storage 对象插入 API 参考:
推荐阅读
- scala - 是否有维护插入顺序的 Scala 集合?
- php - 我想获取两个表数据然后获取百分比金额
- python - 长测试用例超时,子字符串游戏
- bash - 在 bash 中在三元运算符 ($var -eq 0 ? 1 : 0) 中使用 -eq 时出错
- android - 将 SearchView 添加到 RecyclerView 列表
- vue.js - Vue-cli-service 服务构建完成回调?
- javascript - 无法读取自定义验证器和必需的属性 - Angular
- elm - 分区列表分为 2 个以上的部分
- python - 列表到混合维度矩阵
- azure - Web API 错误 - 此请求已被阻止;内容必须通过 HTTPS 提供