When trying to upload an image is giving problems and would like to know what the problem is and how to solve it.
Amazon request:
public void amazon() {
String fileName = photoFile.getName();
long mTotalFileBytes;
ObjectMetadata metadata = new ObjectMetadata();
metadata.setContentLength(mTotalFileBytes = photoFile.length());
metadata.setContentType("image/".concat(fileName));
CognitoCachingCredentialsProvider credentialsProvider = new CognitoCachingCredentialsProvider(
getApplicationContext(),
"us-east-1:my-cognito-code",
Regions.US_EAST_1
);
amazonS3Client = new AmazonS3Client(credentialsProvider);
amazonS3Client.setRegion(Region.getRegion(Regions.SA_EAST_1));
try {
por = new PutObjectRequest(bucket, fileName, new FileInputStream(photoFile), metadata);
if (postImageAsyncTask == null) {
postImageAsyncTask = new PostImageAsyncTask();
}
postImageAsyncTask.executeOnExecutor(AsyncTask.THREAD_POOL_EXECUTOR);
} catch (FileNotFoundException e) {
e.printStackTrace();
}
amazonUrl = amazonS3Client.getResourceUrl(bucket, fileName);
Log.e(">>>>>URL", ">>>>>" + amazonUrl);
}
AsyncTask:
public class PostImageAsyncTask extends AsyncTask<Object, Object, PutObjectResult> {
public PostImageAsyncTask() {
super();
}
@Override
protected PutObjectResult doInBackground(Object... params) {
try {
return amazonS3Client.putObject(por);
} catch (AmazonServiceException e) {
return null;
} catch (AmazonClientException f) {
return null;
}
}
@Override
protected void onPostExecute(PutObjectResult result) {
if (!isCancelled()) {
if (result != null) {
docsIDController.pictureFinishedSendingToS3(amazonUrl);
} else {
postImageAsyncTask.cancel(true);
if (RECONECT_TIME_DELAY < MAX_TIME_DELAY) {
if ((snackbar == null || !snackbar.isShown())) {
snackbar = Snackbar.make(coordinatorLayoutView, "Ocorreu um problema de conexão, aguardando dispositivo se reconectar", Snackbar.LENGTH_INDEFINITE);
snackbar.setActionTextColor(Color.BLUE);
snackbar.setAction("Cancelar", new View.OnClickListener() {
@Override
public void onClick(View view) {
finishedTakingDocIDPicture(null);
}
});
snackbar.show();
}
handler.postDelayed(new Runnable() {
@Override
public void run() {
RECONECT_TIME_DELAY = RECONECT_TIME_DELAY * 2;
postImageAsyncTask.cancel(true);
postImageAsyncTask = new PostImageAsyncTask();
postImageAsyncTask.executeOnExecutor(AsyncTask.THREAD_POOL_EXECUTOR);
}
}, RECONECT_TIME_DELAY);
}
}
} else {
postImageAsyncTask.cancel(true);
}
}
}
Stack trace:
I/AmazonHttpClient: Unable to execute HTTP request: Write error: ssl=0x5c15d378: I/O error during system call, Broken pipe
javax.net.ssl.SSLException: Write error: ssl=0x5c15d378: I/O error during system call, Broken pipe
at org.apache.harmony.xnet.provider.jsse.NativeCrypto.SSL_write(Native Method)
at org.apache.harmony.xnet.provider.jsse.OpenSSLSocketImpl$SSLOutputStream.write(OpenSSLSocketImpl.java:717)
at libcore.net.http.FixedLengthOutputStream.write(FixedLengthOutputStream.java:41)
at com.amazonaws.http.UrlHttpClient.write(UrlHttpClient.java:172)
at com.amazonaws.http.UrlHttpClient.writeContentToConnection(UrlHttpClient.java:129)
at com.amazonaws.http.UrlHttpClient.execute(UrlHttpClient.java:65)
at com.amazonaws.http.AmazonHttpClient.executeHelper(AmazonHttpClient.java:353)
at com.amazonaws.http.AmazonHttpClient.execute(AmazonHttpClient.java:196)
at com.amazonaws.services.s3.AmazonS3Client.invoke(AmazonS3Client.java:4204)
at com.amazonaws.services.s3.AmazonS3Client.putObject(AmazonS3Client.java:1618)
at com.foregon.forid.pictureManagement.boundary.DocsIDUI$PostImageAsyncTask.doInBackground(DocsIDUI.java:488)
at com.foregon.forid.pictureManagement.boundary.DocsIDUI$PostImageAsyncTask.doInBackground(DocsIDUI.java:478)
at android.os.AsyncTask$2.call(AsyncTask.java:287)
at java.util.concurrent.FutureTask$Sync.innerRun(FutureTask.java:305)
at java.util.concurrent.FutureTask.run(FutureTask.java:137)
at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1076)
at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:569)
at java.lang.Thread.run(Thread.java:856)