AWS SDK requires a File
object for uploading data to a bucket. I'm having trouble creating a File object required by transferUtility.upload
. I know new File(selectedImageUri.getPath())
does not work. I've tried reading about how to make a file from a uri, but there doesn't seem to be an easy way of doing that. Should I be using something other than TransferUtility
?
public class SettingsActivity extends AppCompatActivity {
...
private class ChangeSettingsTask extends AsyncTask<Void, Void, Boolean> {
public void uploadData(File image) {
TransferUtility transferUtility =
TransferUtility.builder()
.defaultBucket("some-bucket")
.context(getApplicationContext())
.s3Client(new AmazonS3Client( new BasicAWSCredentials( "something", "something") ))
.build();
TransferObserver uploadObserver =
transferUtility.upload("somefile.jpg", image);
...
}
@Override
protected void onActivityResult(int reqCode, int resultCode, Intent data) {
super.onActivityResult(reqCode, resultCode, data);
if (resultCode == RESULT_OK) {
Uri selectedImageUri = data.getData();
uploadData(new File(selectedImageUri.getPath()));
}
}
}