1

我使用google-api-client for android。我嘗試使用文本數據和圖像文件進行多部分POST請求。用於創建請求的代碼片段如下:Google-api-client for Multipart POST請求

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

內容是鍵值文本內容。因此,我得到錯誤500.

我做錯了什麼?

回答

2

這裏有一個指導如何做媒體上傳與谷歌的API-java-client的位置:

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

這麼說,我做的沒有什麼一定錯了你的代碼,通過。 googleUrl可能不正確,或者內容格式不正確。您可能想嘗試添加URL查詢參數uploadType = multipart,以指定您使用multipart作爲協議。