【问题标题】:Google-api-client for Multipart POST request用于 Multipart POST 请求的 Google-api-client
【发布时间】:2012-11-09 18:38:22
【问题描述】:

我将 google-api-client 用于 android。我尝试使用文本数据和图像文件进行多部分 POST 请求。创建请求的代码 sn-p 如下:

InputStream stream = new FileInputStream(fileToSend);
InputStreamContent photoContent = new InputStreamContent("image/jpeg", stream);
MultipartRelatedContent multiContent =
    new MultipartRelatedContent(content, photoContent); 
HttpRequest request = getRequestFactory().buildPostRequest(googleUrl, multiContent);

content 是键值文本内容。结果我得到错误 500。

我做错了什么?

【问题讨论】:

    标签: android google-api google-api-java-client google-api-client


    【解决方案1】:

    这里有一个关于如何使用 google-api-java-client 进行媒体上传的指南:

    https://code.google.com/p/google-api-java-client/wiki/MediaUpload

    也就是说,我的代码也不一定有任何问题。可能是 googleUrl 不正确,或者内容格式不正确。您可能想尝试添加一个 URL 查询参数 uploadType=multipart 来指定您使用 multipart 作为协议。

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2021-04-27
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多