{"action":"created","issue":{"url":"https://api.github.com/repos/chrsmithdemos/google-api-java-client/issues/897","labels_url":"https://api.github.com/repos/chrsmithdemos/google-api-java-client/issues/897/labels{/name}","comments_url":"https://api.github.com/repos/chrsmithdemos/google-api-java-client/issues/897/comments","events_url":"https://api.github.com/repos/chrsmithdemos/google-api-java-client/issues/897/events","html_url":"https://github.com/chrsmithdemos/google-api-java-client/issues/897","id":59553889,"number":897,"title":"Unable to resuming an interrupted upload","user":{"login":"GoogleCodeExporter","id":9614759,"avatar_url":"https://avatars.githubusercontent.com/u/9614759?v=3","gravatar_id":"","url":"https://api.github.com/users/GoogleCodeExporter","html_url":"https://github.com/GoogleCodeExporter","followers_url":"https://api.github.com/users/GoogleCodeExporter/followers","following_url":"https://api.github.com/users/GoogleCodeExporter/following{/other_user}","gists_url":"https://api.github.com/users/GoogleCodeExporter/gists{/gist_id}","starred_url":"https://api.github.com/users/GoogleCodeExporter/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/GoogleCodeExporter/subscriptions","organizations_url":"https://api.github.com/users/GoogleCodeExporter/orgs","repos_url":"https://api.github.com/users/GoogleCodeExporter/repos","events_url":"https://api.github.com/users/GoogleCodeExporter/events{/privacy}","received_events_url":"https://api.github.com/users/GoogleCodeExporter/received_events","type":"User","site_admin":false},"labels":[{"url":"https://api.github.com/repos/chrsmithdemos/google-api-java-client/labels/auto-migrated","name":"auto-migrated","color":"ededed"},{"url":"https://api.github.com/repos/chrsmithdemos/google-api-java-client/labels/Priority-Medium","name":"Priority-Medium","color":"ededed"},{"url":"https://api.github.com/repos/chrsmithdemos/google-api-java-client/labels/Type-Defect","name":"Type-Defect","color":"ededed"}],"state":"open","locked":false,"assignee":null,"milestone":null,"comments":3,"created_at":"2015-03-02T21:26:48Z","updated_at":"2015-03-02T21:26:49Z","closed_at":null,"body":"```\ngoogle-api-java-client-1.18.0-rc\ngoogle-api-services-drive-v2-rev135-1.18.0-rc\n\nJava environment: Android 443\n\nDescribe the problem.\n\nIt seems that MediaHttpUploader.upload() did not handle resume upload well. \nThe reason is that \"1) Request the upload status.\" mentioned in \"Google Drive \nSDK, Upload Files\" always fail to get \"Content-Range\".\nhttps://developers.google.com/drive/web/manage-uploads#resumable\n\nMy test step is try to disconnect WiFi/connect to another WiFi during upload, \nand then upload the same file again, but it always upload the file from \nbeginning.\n\nCode(cannot resume an interrupted upload):\n\ninsert = getDriveService().files().insert(fileMetadata, mediaContent);\nMediaHttpUploader mediaUploader = insert.getMediaHttpUploader();\nmediaUploader.setDirectUploadEnabled(false);\nmediaUploader.setProgressListener(mUploadFileProgressListener);\nmediaUploader.setChunkSize(MediaHttpUploader.MINIMUM_CHUNK_SIZE);\nmediaUploader.upload(insert.buildHttpRequestUrl());\n\n\nHow would you expect it to be fixed?\n\n1) Google drive server should respond \"Content-Range\" with \"HTTP/1.1 308 Resume \nIncomplete\"\n2) If server is allow to NOT response \"Content-Range\", the way to solve it is \npolling \"Content-Range\" all the time during upload. Thus, it able to resuming \nan interrupted upload by \"Resume the upload from the point where it left off.\"\n\n\n```\n\nOriginal issue reported on code.google.com by `kaifu.c...@gmail.com` on 15 Aug 2014 at 8:18"},"comment":{"url":"https://api.github.com/repos/chrsmithdemos/google-api-java-client/issues/comments/76828653","html_url":"https://github.com/chrsmithdemos/google-api-java-client/issues/897#issuecomment-76828653","issue_url":"https://api.github.com/repos/chrsmithdemos/google-api-java-client/issues/897","id":76828653,"user":{"login":"GoogleCodeExporter","id":9614759,"avatar_url":"https://avatars.githubusercontent.com/u/9614759?v=3","gravatar_id":"","url":"https://api.github.com/users/GoogleCodeExporter","html_url":"https://github.com/GoogleCodeExporter","followers_url":"https://api.github.com/users/GoogleCodeExporter/followers","following_url":"https://api.github.com/users/GoogleCodeExporter/following{/other_user}","gists_url":"https://api.github.com/users/GoogleCodeExporter/gists{/gist_id}","starred_url":"https://api.github.com/users/GoogleCodeExporter/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/GoogleCodeExporter/subscriptions","organizations_url":"https://api.github.com/users/GoogleCodeExporter/orgs","repos_url":"https://api.github.com/users/GoogleCodeExporter/repos","events_url":"https://api.github.com/users/GoogleCodeExporter/events{/privacy}","received_events_url":"https://api.github.com/users/GoogleCodeExporter/received_events","type":"User","site_admin":false},"created_at":"2015-03-02T21:26:49Z","updated_at":"2015-03-02T21:26:49Z","body":"```\nHello, \n\nSine the issue happen rate is 100%, I suggest you to get upload ID by yourself.\nOr you can get upload ID based on below method:\n\n\tprivate String getUploadID(Uri fileUri, String token) {\t\t\t\n\t\tLog.d(LOG_TAG, \"[sendResumableHttpRequest] +++\");\n\t\t\n\t\tString upload_id = \"\";\n \n\t\tjava.io.File fileContent = new java.io.File(fileUri.getPath());\n\t\tString fileName = fileContent.getName();\n\t\tString contentLength = String.valueOf(fileContent.length());\n\t\tString mimeType = getMimeFromURI(fileUri);\n\t\t\n\t\tLog.d(LOG_TAG, \"[sendResumableHttpRequest] fileName : \" + fileName);\n\t\tLog.d(LOG_TAG, \"[sendResumableHttpRequest] contentLength : \" + contentLength);\n\t\tLog.d(LOG_TAG, \"[sendResumableHttpRequest] mimeType : \" + mimeType);\n\t\t\n\t\ttry {\n\t\t\tString url = \"https://www.googleapis.com/upload/drive/v2/files?uploadType=resumable\";\n\t\t\tURL obj = new URL(url);\n\t\t\tHttpsURLConnection con = (HttpsURLConnection) obj.openConnection();\n\t \n\t\t\t//add reuqest header\n\t\t\tcon.setRequestMethod(\"POST\");\n\t\t\tcon.setRequestProperty(\"Authorization\", \"Bearer \" + token);\n\t\t\tcon.setRequestProperty(\"Content-Type\", \"application/json; charset=UTF-8\");\n\t\t\tcon.setRequestProperty(\"X-Upload-Content-Type\", mimeType);\n\t\t\tcon.setRequestProperty(\"X-Upload-Content-Length\", contentLength);\t\t\n\n\t\t\tJSONObject jobj = new JSONObject();\n\t\t    jobj.put(\"title\", fileName);\n\t\t    byte[] postData = jobj.toString().getBytes();\t\t\t\n\t\t\t\n\t\t\t// Send post request\n\t\t\tcon.setDoOutput(true);\n\t\t\tDataOutputStream wr = new DataOutputStream(con.getOutputStream());\n\t\t\twr.write(postData);\n\t\t\twr.flush();\n\t\t\twr.close();\n\t \n\t\t\tint responseCode = con.getResponseCode();\n\t\t\tString location = con.getHeaderField(\"Location\");\n\t\t\tif (location.contains(\"upload_id\")) {\n\t\t\t\tString[] uploadParameters = location.split(\"upload_id\");\n\t\t\t\tupload_id = uploadParameters[1].replace(\"=\", \"\");\n\t\t\t}\n\t\t\t\n\t\t\tLog.d(LOG_TAG, \"[sendResumableHttpRequest] Response Code : \" + responseCode);\n\t\t\tLog.d(LOG_TAG, \"[sendResumableHttpRequest] Response Location : \" + location);\n\t\t\tLog.d(LOG_TAG, \"[sendResumableHttpRequest] Response uploadID : \" + upload_id);\n\t \n\t\t\tBufferedReader in = new BufferedReader(\n\t\t\t        new InputStreamReader(con.getInputStream()));\n\t\t\tString inputLine;\n\t\t\tStringBuffer response = new StringBuffer();\n\t \n\t\t\twhile ((inputLine = in.readLine()) != null) {\n\t\t\t\tresponse.append(inputLine);\n\t\t\t}\n\t\t\tin.close();\n\t\t} catch (Exception e) {\n\t\t\te.printStackTrace();\t\t\t\n\t\t}\t\t\t\t\n\t\t\n\t\tLog.d(LOG_TAG, \"[sendResumableHttpRequest] ---\");\n\t\t\n\t\treturn upload_id;\n\t}\n```\n\nOriginal comment by `kaifu.c...@gmail.com` on 29 Aug 2014 at 9:17"}}