Created
May 29, 2017 15:36
-
-
Save miroslavign/e4169b889ae90a7a4e205db500b10321 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
private Observable<SentToS3Event> getAmazonObservable(String newFilename) { | |
Observable<SentToS3Event> amazonObservable = Observable.defer(new Func0<Observable<SentToS3Event>>() { | |
@Override | |
public Observable<SentToS3Event> call() { | |
return Observable.create((ObservableEmitter<SentToS3Event> subscriber) -> { | |
final PutObjectRequest putObjectRequest = new PutObjectRequest(AmazonS3FetchParams.MY_BUCKET_NAME, newFilename, new java.io.File(fileURI)) | |
.withCannedAcl(CannedAccessControlList.PublicRead) | |
.withStorageClass(StorageClass.Standard); | |
putObjectRequest.setGeneralProgressListener(new S3ProgressListener() { | |
@Override | |
public void onPersistableTransfer(PersistableTransfer persistableTransfer) { | |
} | |
@Override | |
public void progressChanged(ProgressEvent progressEvent) { | |
if (progressEvent.getEventCode() == ProgressEvent.COMPLETED_EVENT_CODE) { | |
Logger.d("TRANSFER finished: " + progressEvent.getBytesTransferred() + " bytes"); | |
SentToS3Event sentEvent = new SentToS3Event(fileName, fileURI, position, | |
0, from, nrRetry, messageDbId, getAmazonImageUrl(fileName)); | |
subscriber.onNext(sentEvent); | |
subscriber.onComplete(); | |
} else if (progressEvent.getEventCode() == ProgressEvent.FAILED_EVENT_CODE) { | |
SentToS3Event sentEvent = new SentToS3Event(fileName, fileURI, position, | |
-1, from, nrRetry, messageDbId, getAmazonImageUrl(fileName)); | |
subscriber.onNext(sentEvent); | |
subscriber.onComplete(); | |
} | |
} | |
}); | |
PutObjectResult objectResult = s3Client.putObject(putObjectRequest); | |
}); | |
} | |
}); | |
return amazonObservable; | |
} |
Author
miroslavign
commented
May 29, 2017
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment