mercredi 22 juillet 2015

Where can I find WORKING samples of Amazon's S3 Image Uploader for Android

I have spent the past 2 days struggling with Amazon's S3 SDK for Android. I was able to get the Java one (in Eclipse) working without any problems whatsoever; I could upload pictures, download them, and it would be no problem. Changing gears to Android, however, and I have had no luck. Currently, with this selected code:

AmazonS3Client s3 = new AmazonS3Client( new BasicAWSCredentials(
        Constants.AWS_ACCESS_KEY, Constants.AWS_SECRET_ACCESS_KEY ) );
        //These are correct, I have already confirmed.

ObjectMetadata metaData = new ObjectMetadata();
metaData.setContentType("jpeg"); //binary data

PutObjectRequest putObjectRequest = new PutObjectRequest(
        Constants.BUCKETNAME, Constants.KEY3, new File(selectedImageUri.getPath())
); 
//selectedImageUri is correct as well, 
//(file:///storage/emulated/0/MyDir/image_1437585138776.jpg) 
putObjectRequest.setMetadata(metaData);

s3.putObject(putObjectRequest); //Errors out here

I am getting multiple errors, the most common of which is this:

AmazonHttpClient﹕ Unable to execute HTTP request: Write error: ssl=0xb8cefc10: I/O error during system call, Connection reset by peer
    javax.net.ssl.SSLException: Write error: ssl=0xb8cefc10: I/O error during system call, Connection reset by peer
            at com.android.org.conscrypt.NativeCrypto.SSL_write(Native Method)

I have done a ton of research and had no luck finding WORKING code. I used this link from Amazon: http://ift.tt/1Dvib2c Without it working for me at all. They say up top it is deprecated, but I cannot find any links to working code. If you follow the SDK links to 'android sample code' files, their github repo (here: http://ift.tt/1iaLSfR) contains zero code on the topic of uploading files (namely pictures).

Does anyone have ANY idea where I can find some working code that shows how to just upload a stupid picture to my bucket?!??! (Wish I knew why this was so simple in Java/ Eclipse and not so in Android / Studio).

PS: I have my api_key in the correct assets folder, my credentials are correct for login, the image is under 5mb, and this is being run on a background (async) thread so as to not be on the main thread.

-Pat




Aucun commentaire:

Enregistrer un commentaire