Open GoogleCodeExporter opened 9 years ago
Thanks for your feedback. We're looking into your issue. Please stay tuned for
updates.
Original comment by wonder...@google.com
on 22 Aug 2014 at 6:03
Hi, to help us debugging, can you provide an uploadId? It will be a query
parameter on additional resumable upload requests beyond the first one.
Original comment by wonder...@google.com
on 28 Aug 2014 at 11:51
Hello,
Sine the issue happen rate is 100%, I suggest you to get upload ID by yourself.
Or you can get upload ID based on below method:
private String getUploadID(Uri fileUri, String token) {
Log.d(LOG_TAG, "[sendResumableHttpRequest] +++");
String upload_id = "";
java.io.File fileContent = new java.io.File(fileUri.getPath());
String fileName = fileContent.getName();
String contentLength = String.valueOf(fileContent.length());
String mimeType = getMimeFromURI(fileUri);
Log.d(LOG_TAG, "[sendResumableHttpRequest] fileName : " + fileName);
Log.d(LOG_TAG, "[sendResumableHttpRequest] contentLength : " + contentLength);
Log.d(LOG_TAG, "[sendResumableHttpRequest] mimeType : " + mimeType);
try {
String url = "https://www.googleapis.com/upload/drive/v2/files?uploadType=resumable";
URL obj = new URL(url);
HttpsURLConnection con = (HttpsURLConnection) obj.openConnection();
//add reuqest header
con.setRequestMethod("POST");
con.setRequestProperty("Authorization", "Bearer " + token);
con.setRequestProperty("Content-Type", "application/json; charset=UTF-8");
con.setRequestProperty("X-Upload-Content-Type", mimeType);
con.setRequestProperty("X-Upload-Content-Length", contentLength);
JSONObject jobj = new JSONObject();
jobj.put("title", fileName);
byte[] postData = jobj.toString().getBytes();
// Send post request
con.setDoOutput(true);
DataOutputStream wr = new DataOutputStream(con.getOutputStream());
wr.write(postData);
wr.flush();
wr.close();
int responseCode = con.getResponseCode();
String location = con.getHeaderField("Location");
if (location.contains("upload_id")) {
String[] uploadParameters = location.split("upload_id");
upload_id = uploadParameters[1].replace("=", "");
}
Log.d(LOG_TAG, "[sendResumableHttpRequest] Response Code : " + responseCode);
Log.d(LOG_TAG, "[sendResumableHttpRequest] Response Location : " + location);
Log.d(LOG_TAG, "[sendResumableHttpRequest] Response uploadID : " + upload_id);
BufferedReader in = new BufferedReader(
new InputStreamReader(con.getInputStream()));
String inputLine;
StringBuffer response = new StringBuffer();
while ((inputLine = in.readLine()) != null) {
response.append(inputLine);
}
in.close();
} catch (Exception e) {
e.printStackTrace();
}
Log.d(LOG_TAG, "[sendResumableHttpRequest] ---");
return upload_id;
}
Original comment by kaifu.c...@gmail.com
on 29 Aug 2014 at 9:17
Original issue reported on code.google.com by
kaifu.c...@gmail.com
on 15 Aug 2014 at 8:18