folder write

This commit is contained in:
Page Asgardius 2022-12-28 20:45:40 -07:00
parent b73ec1e44b
commit a8b6a2d019

View file

@ -3,6 +3,7 @@ package asgardius.page.s3manager;
import static android.content.ContentValues.TAG; import static android.content.ContentValues.TAG;
import androidx.appcompat.app.AppCompatActivity; import androidx.appcompat.app.AppCompatActivity;
import androidx.documentfile.provider.DocumentFile;
import android.app.Activity; import android.app.Activity;
import android.content.Context; import android.content.Context;
@ -33,7 +34,7 @@ import java.io.OutputStream;
public class Downloader extends AppCompatActivity { public class Downloader extends AppCompatActivity {
String username, password, endpoint, bucket, filename, prefix, location; String username, password, endpoint, bucket, filename, prefix, location;
Uri fileuri; Uri fileuri, filepath;
Region region; Region region;
S3ClientOptions s3ClientOptions; S3ClientOptions s3ClientOptions;
AWSCredentials myCredentials; AWSCredentials myCredentials;
@ -43,6 +44,7 @@ public class Downloader extends AppCompatActivity {
Button fileDownload; Button fileDownload;
Thread downloadFile, downloadProgress; Thread downloadFile, downloadProgress;
S3Object object; S3Object object;
DocumentFile document;
boolean started = false; boolean started = false;
boolean cancel = false; boolean cancel = false;
boolean isfolder = false; boolean isfolder = false;
@ -118,9 +120,15 @@ public class Downloader extends AppCompatActivity {
//Your code goes here //Your code goes here
//s3client.createBucket(bucket, location); //s3client.createBucket(bucket, location);
//System.out.println(fkey); //System.out.println(fkey);
document = DocumentFile.fromTreeUri(getApplicationContext(), fileuri);
object = s3client.getObject(bucket, prefix+filename); object = s3client.getObject(bucket, prefix+filename);
filesize = (object.getObjectMetadata().getContentLength())/1024; filesize = (object.getObjectMetadata().getContentLength())/1024;
writeContentToFile(fileuri, object); if (isfolder) {
filepath = document.createFile(null, filename).getUri();
writeContentToFile(filepath, object);
} else {
writeContentToFile(fileuri, object);
}
runOnUiThread(new Runnable() { runOnUiThread(new Runnable() {
@Override @Override
public void run() { public void run() {