migrated to aws sdk

This commit is contained in:
Page Asgardius 2022-08-28 12:42:34 -07:00
parent 737296e213
commit b5590c6076
3 changed files with 42 additions and 2 deletions

View file

@ -36,7 +36,11 @@ dependencies {
implementation 'com.google.android.material:material:1.4.0' implementation 'com.google.android.material:material:1.4.0'
implementation 'androidx.constraintlayout:constraintlayout:2.0.4' implementation 'androidx.constraintlayout:constraintlayout:2.0.4'
implementation 'com.google.android.exoplayer:exoplayer:2.18.1' implementation 'com.google.android.exoplayer:exoplayer:2.18.1'
implementation("io.minio:minio:8.4.3") // BEGIN AWS DEPENDENCIES
def aws_version = "2.16.+"
implementation "com.amazonaws:aws-android-sdk-s3:$aws_version"
implementation ("com.amazonaws:aws-android-sdk-mobile-client:$aws_version") { transitive = true }
// END AWS DEPENDENCIES
testImplementation 'junit:junit:4.13.2' testImplementation 'junit:junit:4.13.2'
androidTestImplementation 'androidx.test.ext:junit:1.1.3' androidTestImplementation 'androidx.test.ext:junit:1.1.3'
androidTestImplementation 'androidx.test.espresso:espresso-core:3.4.0' androidTestImplementation 'androidx.test.espresso:espresso-core:3.4.0'

View file

@ -1,5 +1,9 @@
package asgardius.page.s3manager; package asgardius.page.s3manager;
import static com.amazonaws.regions.RegionUtils.getRegion;
import static com.amazonaws.regions.Regions.US_EAST_1;
import static com.amazonaws.services.s3.S3ClientOptions.DEFAULT_PATH_STYLE_ACCESS;
import androidx.appcompat.app.AppCompatActivity; import androidx.appcompat.app.AppCompatActivity;
import android.content.Intent; import android.content.Intent;
@ -7,8 +11,20 @@ import android.os.Bundle;
import android.view.View; import android.view.View;
import android.widget.Button; import android.widget.Button;
import com.amazonaws.auth.AWSCredentials;
import com.amazonaws.auth.BasicAWSCredentials;
import com.amazonaws.regions.Region;
import com.amazonaws.services.s3.AmazonS3;
import com.amazonaws.services.s3.AmazonS3Client;
import com.amazonaws.services.s3.S3ClientOptions;
import com.amazonaws.services.s3.model.GeneratePresignedUrlRequest;
import java.net.URL;
public class MainActivity extends AppCompatActivity { public class MainActivity extends AppCompatActivity {
static boolean DEFAULT_PATH_STYLE_ACCESS = true;
@Override @Override
protected void onCreate(Bundle savedInstanceState) { protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState); super.onCreate(savedInstanceState);
@ -19,11 +35,28 @@ public class MainActivity extends AppCompatActivity {
@Override @Override
public void onClick(View view) { public void onClick(View view) {
//buttonaction //buttonaction
videoplayer("https://video.asgardius.company/download/videos/41780585-a935-4d53-84c8-45ce97141231-480.mp4"); s3test();
//videoplayer("https://video.asgardius.company/download/videos/41780585-a935-4d53-84c8-45ce97141231-480.mp4");
} }
}); });
} }
private void s3test() {
Region region = Region.getRegion(US_EAST_1);
S3ClientOptions s3ClientOptions = S3ClientOptions.builder().build();
s3ClientOptions.setPathStyleAccess(true);
AWSCredentials myCredentials = new BasicAWSCredentials(getResources().getString(R.string.access_key), getResources().getString(R.string.secret_key));
AmazonS3 s3client = new AmazonS3Client(myCredentials, region);
s3client.setEndpoint(getResources().getString(R.string.endpoint_url));
s3client.setS3ClientOptions(s3ClientOptions);
//s3client.setRegion(getRegion("asteroid"));
GeneratePresignedUrlRequest request = new GeneratePresignedUrlRequest(getResources().getString(R.string.bucketname), getResources().getString(R.string.objectname));
URL objectURL = s3client.generatePresignedUrl(request);
videoplayer(objectURL.toString());
}
private void videoplayer(String url) { private void videoplayer(String url) {
Intent intent = new Intent(this, VideoPlayer.class); Intent intent = new Intent(this, VideoPlayer.class);
@ -31,4 +64,5 @@ public class MainActivity extends AppCompatActivity {
startActivity(intent); startActivity(intent);
} }
} }

View file

@ -5,6 +5,8 @@
<string name="endpoint_url">s3server</string> <string name="endpoint_url">s3server</string>
<string name="access_key">username</string> <string name="access_key">username</string>
<string name="secret_key">password</string> <string name="secret_key">password</string>
<string name="bucketname">bucket</string>
<string name="objectname">object</string>
<string name="video_test_button">Video Test</string> <string name="video_test_button">Video Test</string>
<string name="media_load_fail">Cannot load media file</string> <string name="media_load_fail">Cannot load media file</string>
<string name="dummy_button">Dummy Button</string> <string name="dummy_button">Dummy Button</string>