I have a small Java program that enables a user to Upload/Download files to/from Amazon S3. I have a 'Cancel' button and would like to cancel the transfer once this button is pressed.
It looks like there is an abort()
method when Downloading which seems to be working, however I am not sure how to go about aborting an Upload. I am using a TransferManager to upload the files. I have tried calling transferManager.shutdownNow()
along with transferManager.abortMultipartUploads()
, however the file still shows up in the S3 Management Console as if the transfer was not aborted. Am I doing something wrong?
By default, when you upload the file with same name. It will overwrite the existing file. In case you want to have the previous file available, you need to enable versioning in the bucket.
Reference the S3 developer guide for technical details on the following request types: PUT, COPY, POST, LIST, GET, SELECT, Lifecycle Transition, and Data Retrievals. DELETE and CANCEL requests are free. LIST requests for any storage class are charged at the same rate as S3 Standard PUT, COPY, and POST requests.
If the version ID maps to a specific object version, Amazon S3 deletes the specific version of the object. If the version ID maps to the delete marker of that object, Amazon S3 deletes the delete marker. This makes the object reappear in your bucket.
In my program, I call transferManager.upload()
method to upload a PutObjectRequest
object, and then it returns an Upload
object, which contains abort()
API. So I just call upload.abort()
to cancel the transfer. I hope this helps.:)
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With