I also use the Amazon SDK to upload to S3 and record the Bitmap
in an app cache folder and then move to the SDK.
Something like:
@NonNull
public static File storeOnCache(Context context, Bitmap bitmap) throws IOException {
File cacheDir = context.getCacheDir();
File file = new File(cacheDir, generateRandomFilename("jpg"));
FileOutputStream out = new FileOutputStream(file);
bitmap.compress(Bitmap.CompressFormat.JPEG, 100, out);
out.flush();
out.close();
return file;
}
Where the generateRandomFileName
is a simple method that generates a name for not having conflict.
@NonNull
public static String generateRandomFilename(@Nullable String extension) {
return new StringBuilder(50)
.append(System.currentTimeMillis())
.append((int) (Math.random() * 10000.0))
.append(".")
.append(extension)
.toString();
}
Ai may be worth having a later treatment to remove the file at the end of the upload.
Using:
Bitmap bitmap = ...
File bitmapOnCache = storeOnCache(this, bitmap);
String fileName = bitmapOnCache.getName();
// Dependendo da forma como irá fazer:
ObjectMetadata metadata = new ObjectMetadata();
metadata.setContentLength(mTotalFileBytes = bitmapOnCache.length());
metadata.setContentType("image/".concat(getExtension(fileName)));
PutObjectRequest por = new PutObjectRequest("BUCKET_NAME", fileName, new FileInputStream(bitmapOnCache), metadata);
AmazonS3Client client = ...
client.putObject(por);
If your problem is send bitmap, because it posted the code to catch him? And what mistake you get?
– Androiderson
I left there in case there is any error in the way to catch it, and so there is a better understanding of the steps I am following and just do not have a mistake because I do not know how to send a bitmap to Amazon S3
– Aleff Matos
It doesn’t matter how you get the bitmap. But what problem are you facing when sending it? Show the code and error.
– Androiderson
You will probably have to create a webservice
– Guilherme Nascimento
But using Amazon’s sdk it no longer makes the direct connection when it creates a connection client?
– Aleff Matos
What I noticed, I have to pass a File instead of a Bitmap but how to do it to send?
– Aleff Matos