{"action":"opened","issue":{"url":"https://api.github.com/repos/aws/aws-sdk-android/issues/44","labels_url":"https://api.github.com/repos/aws/aws-sdk-android/issues/44/labels{/name}","comments_url":"https://api.github.com/repos/aws/aws-sdk-android/issues/44/comments","events_url":"https://api.github.com/repos/aws/aws-sdk-android/issues/44/events","html_url":"https://github.com/aws/aws-sdk-android/issues/44","id":87609744,"number":44,"title":"Upload does not resume","user":{"login":"suraj9781","id":8064400,"avatar_url":"https://avatars.githubusercontent.com/u/8064400?v=3","gravatar_id":"","url":"https://api.github.com/users/suraj9781","html_url":"https://github.com/suraj9781","followers_url":"https://api.github.com/users/suraj9781/followers","following_url":"https://api.github.com/users/suraj9781/following{/other_user}","gists_url":"https://api.github.com/users/suraj9781/gists{/gist_id}","starred_url":"https://api.github.com/users/suraj9781/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/suraj9781/subscriptions","organizations_url":"https://api.github.com/users/suraj9781/orgs","repos_url":"https://api.github.com/users/suraj9781/repos","events_url":"https://api.github.com/users/suraj9781/events{/privacy}","received_events_url":"https://api.github.com/users/suraj9781/received_events","type":"User","site_admin":false},"labels":[],"state":"open","locked":false,"assignee":null,"milestone":null,"comments":0,"created_at":"2015-06-12T05:13:53Z","updated_at":"2015-06-12T05:13:53Z","closed_at":null,"body":"Hi there,\r\n\r\nFor Low level api:\r\nI am using low level api for multipart upload .When i kill the app and try to resume upload it doesnot resume instead it restarts.When i try resume the upload i am getting different upload id fro same key and bucket.\r\nWhen tried to store the upload id obtain when i start upload and try to user that upload id then upload resumed but it did not complete.I got following error exception:\r\n06-11 16:55:51.374  22136-22388/com.sharez D/UploadObjectMPU﹕ Error !!! :: One or more of the specified parts could not be found.  The part may not have been uploaded, or the specified entity tag may not match the part's entity tag. (Service: Amazon S3; Status Code: 400; Error Code: InvalidPart; Request ID: 264F4CFFAE836648)\r\n.Following is the code used.\r\n\r\n/**\r\n\t * This method is useful to resume update\r\n\t * \r\n\t * @param pInitResponse\r\n\t * @param pS3Client\r\n\t * @param pPartETags\r\n\t * @return\r\n\t */\r\n\tprivate int retrievePartDetails(\r\n\t\t\tInitiateMultipartUploadResult pInitResponse,\r\n\t\t\tAmazonS3Client pS3Client, List<PartETag> pPartETags) {\r\n\t\t// for new upload this upload id may be null or empty for paused upload\r\n\t\t// this has some values\r\n\t\tString  lUploadId =pInitResponse.getUploadId();\r\n\t\tLog.d(TAG, \"retrievePartDetails():   uploadId = \" + lUploadId);\r\n\t\tListPartsRequest lPartsRequest = new ListPartsRequest(mBucketName,\r\n\t\t\t\tmKeyName, lUploadId);\r\n\t\tPartListing lListing = pS3Client.listParts(lPartsRequest);\r\n\t\tList<PartSummary> lList = lListing.getParts();\r\n\r\n\t\tfor (PartSummary lPartSummary : lList) {\r\n\t\t\tPartETag lPartETag = new PartETag(lPartSummary.getPartNumber(),\r\n\t\t\t\t\tlPartSummary.getETag());\r\n\t\t\tpPartETags.add(lPartETag);\r\n\t\t}\r\n\r\n\t\treturn (lList.size() < 1) ? 1 : lList.get(lList.size() - 1)\r\n\t\t\t\t.getPartNumber() + 1;\r\n\t}\r\n\r\n/**\r\n\t * get a upload request\r\n\t * \r\n\r\n\t * \r\n\t * @return\r\n\t */\r\n\r\nprivate InitiateMultipartUploadRequest getUploadRequest() {\r\n\r\n\t\treturn new InitiateMultipartUploadRequest(mBucketName, mKeyName);\r\n\t\t// return new InitiateMultipartUploadRequest(mBucketName, mKeyName);\r\n\t}\r\n\r\n\r\n\t/**\r\n\t * Intiate mutipart request\r\n\t * \r\n\t * @param pS3LowLevelUploadTask\r\n\t * @param pFile\r\n\t */\r\nprivate void initateMutipartRequest(\r\n\t\t\tS3LowLevelUploadTask pS3LowLevelUploadTask, File pFile) {\r\n\t\t// Create a list of UploadPartResponse objects. You get one of these\r\n\t\t// for each part upload.\r\n\t\tList<PartETag> lPartETags = new ArrayList<PartETag>();\r\n\t\ttry {\r\n\r\n\t\t\tmInitResponse = mS3Client\r\n\t\t\t\t\t.initiateMultipartUpload(getUploadRequest());\r\n\r\n\t\t\t// required for resume\r\n\t\t\tint lStartPart = retrievePartDetails(mInitResponse, mS3Client,\r\n\t\t\t\t\tlPartETags);\r\n\t\t\tLog.d(TAG, \"lStartPart = \" + lStartPart);\r\n\r\n\t\t\tlong lFilePosition = (lStartPart - 1) * mPartSize;\r\n\t\t\tLog.d(TAG, \"filePosition = \" + lFilePosition);\r\n\t\t\t// show default progress for multipart upload\r\n\t\t\t\r\n\r\n\t\t\tfor (int i = lStartPart; lFilePosition < mFileSize; i++) {\r\n\r\n\t\t\t\t\r\n\t\t\t\t// Last part can be less than 5 MB. Adjust part size.\r\n\t\t\t\tmPartSize = Math.min(mPartSize, (mFileSize - lFilePosition));\r\n\r\n\t\t\t\t// Create request to upload a part.\r\n\t\t\t\tmUploadRequest = new UploadPartRequest()\r\n\t\t\t\t\t\t.withBucketName(mBucketName).withKey(mKeyName)\r\n\t\t\t\t\t\t.withUploadId(mInitResponse.getUploadId())\r\n\t\t\t\t\t\t.withPartNumber(i).withFileOffset(lFilePosition)\r\n\t\t\t\t\t\t.withFile(pFile).withPartSize(mPartSize)\r\n\t\t\t\t\t\t.withGeneralProgressListener(this);\r\n\r\n\t\t\t\t// Upload part and add response to our list.\r\n\t\t\t\tlPartETags.add(mS3Client.uploadPart(mUploadRequest)\r\n\t\t\t\t\t\t.getPartETag());\r\n\t\t\t\tlFilePosition += mPartSize;\r\n\t\t\t\t// request update percentage to UI\r\n\r\n\t\t\t\tpS3LowLevelUploadTask.updateProgress(getPercentageUpload(\r\n\t\t\t\t\t\tmFileSize, lFilePosition));\r\n\t\t\t\tLog.d(TAG, \"filePosition = \" + lFilePosition);\r\n\r\n\t\t\t}\r\n\r\n\r\n\r\n\r\n\t\t\t\r\n\t\t\t\tperfromComplete(mInitResponse, lPartETags, mS3Client);\r\n\t\t\t\t\r\n\t\t\t\t\r\n\r\n\t\t\t\r\n\r\n\t\t} catch (AbortedException lAse) {\r\n\t\t\tlAse.printStackTrace();\r\n\t\t} catch (Exception e) {\r\n\t\t\tLog.d(TAG, \"Error !!! :: \" + e.getMessage());\r\n\t\t\te.printStackTrace();\r\n\t\t\r\n\t\t}\r\n\t\t\r\n\t}\r\n\r\n/**\r\n\t * Mark file has been successfully uploaded\r\n\t * \r\n\t * @param pInitResponse\r\n\t * @param pPartETags\r\n\t * @param pS3Client\r\n\t * @param pS3LowLevelUploadTask\r\n\t */\r\n\tprivate void perfromComplete(InitiateMultipartUploadResult pInitResponse,\r\n\t\t\tList<PartETag> pPartETags, AmazonS3Client pS3Client) {\r\n\t\tCompleteMultipartUploadRequest compRequest = new CompleteMultipartUploadRequest(\r\n\t\t\t\tmBucketName, mKeyName, pInitResponse.getUploadId(), pPartETags);\r\n\t\tpS3Client.completeMultipartUpload(compRequest);\r\n\r\n\t}\r\n\r\n\r\nFor high level api:\r\n\r\n/**To save transfer state*/\r\npublic void saveTransferState(PersistableTransfer persistableTransfer, String fileName) {\r\n  // Create a new file to store the information.\r\n  File f = new File(fileName);\r\n  if( !f.exists() ) f.createNewFile();\r\n  FileOutputStream fos = new FileOutputStream(f);\r\n  // Serialize the persistable transfer to the file.\r\n  persistableTransfer.serialize(fos);\r\n  fos.close();    \r\n}\r\n\r\n\r\nPutObjectRequest putRequest = new PutObjectRequest(BUCKET_NAME, mKey,file);\r\n// Upload a file to Amazon S3.\r\ntransferManager.upload(putRequest, new S3ProgressListener() {\r\n  ExecutorService executor = Executors.newFixedThreadPool(1);\r\n  @Override\r\n  public void onPersistableTransfer(final PersistableTransfer persistableTransfer) {\r\n        executor.submit(new Runnable() {\r\n          @Override\r\n          public void run() {\r\n              saveTransferState(persistableTransfer, “resume-upload”);\r\n          }\r\n        });\r\n    }\r\n});\r\n\r\n\r\nFor resuming upload:\r\n\r\nString fileName = \"resume-upload\";\r\nFile f = new File (fileName);\r\nif(f.exists()) {\r\n  FileInputStream fis = new FileInputStream(f); \r\n  // Deserialize PersistableUpload information from disk. \r\n  PersistableUpload persistableUpload = PersistableTransfer.deserializeFrom(fis); \r\n  // Call resumeUpload with PersistableUpload. \r\n mUpload =  transferManager.resumeUpload(persistableUpload); \r\ntry {\r\n\r\n\t\t\tif (mUpload != null) {\r\n\r\n\t\t\t\tmUpload.addProgressListener(this);\r\n\r\n\t\t\t\tmUpload.waitForCompletion();\r\n\r\n\t\t\t}\r\n\t\t}\r\n\r\n\t\tcatch (AmazonServiceException e) {\r\n\r\n\t\t\te.printStackTrace();\r\n\r\n\t\t} catch (AmazonClientException e) {\r\n\r\n\t\t\te.printStackTrace();\r\n\r\n\t\t} catch (InterruptedException e) {\r\n\r\n\t\t\te.printStackTrace();\r\n\r\n\t\t} catch (Exception e) {\r\n\t\t\te.printStackTrace();\r\n\t\t}\r\n\t}\r\n  fis.close();\r\n}"}}