folder download

This commit is contained in:
Page Asgardius 2022-12-29 09:16:15 -07:00
parent c1342adcee
commit 44c28dc748
5 changed files with 30 additions and 7 deletions

View file

@ -127,10 +127,12 @@ 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);
if (isfolder) { if (isfolder) {
if (object == null) { document = DocumentFile.fromTreeUri(getApplicationContext(), fileuri);
if (prefix == null) {
orequest = new ListObjectsRequest().withBucketName(bucket).withMaxKeys(1000); orequest = new ListObjectsRequest().withBucketName(bucket).withMaxKeys(1000);
} else {
orequest = new ListObjectsRequest().withBucketName(bucket).withPrefix(prefix).withMaxKeys(1000);
} }
ArrayList<String> objectlist = new ArrayList<String>(); ArrayList<String> objectlist = new ArrayList<String>();
ObjectListing result = s3client.listObjects(orequest); ObjectListing result = s3client.listObjects(orequest);
@ -160,7 +162,7 @@ public class Downloader extends AppCompatActivity {
} }
for (String os : objectlist) { for (String os : objectlist) {
object = s3client.getObject(bucket, os); object = s3client.getObject(bucket, os);
filepath = document.createFile(null, os).getUri(); filepath = document.createFile(null, os.replace(prefix, "")).getUri();
writeContentToFile(filepath, object); writeContentToFile(filepath, object);
} }
} else { } else {
@ -182,7 +184,11 @@ public class Downloader extends AppCompatActivity {
//System.out.println("WakeLock released"); //System.out.println("WakeLock released");
} }
simpleProgressBar.setProgress(100); simpleProgressBar.setProgress(100);
if (isfolder) {
fileDownload.setText(getResources().getString(R.string.batch_download_success));
} else {
fileDownload.setText(getResources().getString(R.string.download_success)); fileDownload.setText(getResources().getString(R.string.download_success));
}
fileDownload.setEnabled(false); fileDownload.setEnabled(false);
//simpleProgressBar.setVisibility(View.INVISIBLE); //simpleProgressBar.setVisibility(View.INVISIBLE);
} }

View file

@ -394,6 +394,9 @@ public class ObjectSelect extends AppCompatActivity {
if (menuItem.getTitle() == getResources().getString(R.string.upload_file_here)) { if (menuItem.getTitle() == getResources().getString(R.string.upload_file_here)) {
//Toast.makeText(ObjectSelect.this, getResources().getString(R.string.pending_feature), Toast.LENGTH_SHORT).show(); //Toast.makeText(ObjectSelect.this, getResources().getString(R.string.pending_feature), Toast.LENGTH_SHORT).show();
upload(); upload();
} else if (menuItem.getTitle() == getResources().getString(R.string.download_folder)) {
//Toast.makeText(ObjectSelect.this, getResources().getString(R.string.pending_feature), Toast.LENGTH_SHORT).show();
download(Name.get(position).toString(), true);
} else if (menuItem.getTitle() == getResources().getString(R.string.object_info)) { } else if (menuItem.getTitle() == getResources().getString(R.string.object_info)) {
objectInfo(prefix + Name.get(position).toString(), Name.get(position).toString()); objectInfo(prefix + Name.get(position).toString(), Name.get(position).toString());
} else if (menuItem.getTitle() == getResources().getString(R.string.file_del)) { } else if (menuItem.getTitle() == getResources().getString(R.string.file_del)) {
@ -421,7 +424,7 @@ public class ObjectSelect extends AppCompatActivity {
//Toast.makeText(MainActivity.this, "You Clicked " + menuItem.getTitle(), Toast.LENGTH_SHORT).show(); //Toast.makeText(MainActivity.this, "You Clicked " + menuItem.getTitle(), Toast.LENGTH_SHORT).show();
if (menuItem.getTitle() == getResources().getString(R.string.download_file)) { if (menuItem.getTitle() == getResources().getString(R.string.download_file)) {
//Toast.makeText(ObjectSelect.this, getResources().getString(R.string.pending_feature), Toast.LENGTH_SHORT).show(); //Toast.makeText(ObjectSelect.this, getResources().getString(R.string.pending_feature), Toast.LENGTH_SHORT).show();
download(Name.get(position).toString()); download(Name.get(position).toString(), false);
} else if (menuItem.getTitle() == getResources().getString(R.string.upload_file_here)) { } else if (menuItem.getTitle() == getResources().getString(R.string.upload_file_here)) {
//Toast.makeText(ObjectSelect.this, getResources().getString(R.string.pending_feature), Toast.LENGTH_SHORT).show(); //Toast.makeText(ObjectSelect.this, getResources().getString(R.string.pending_feature), Toast.LENGTH_SHORT).show();
upload(); upload();
@ -648,16 +651,22 @@ public class ObjectSelect extends AppCompatActivity {
startActivity(intent); startActivity(intent);
} }
private void download(String filename) { private void download(String filename, boolean isfolder) {
Intent intent = new Intent(this, Downloader.class); Intent intent = new Intent(this, Downloader.class);
if(isfolder) {
intent.putExtra("prefix", prefix+filename);
} else {
intent.putExtra("prefix", prefix);
intent.putExtra("filename", filename); intent.putExtra("filename", filename);
}
intent.putExtra("endpoint", endpoint); intent.putExtra("endpoint", endpoint);
intent.putExtra("username", username); intent.putExtra("username", username);
intent.putExtra("password", password); intent.putExtra("password", password);
intent.putExtra("region", location); intent.putExtra("region", location);
intent.putExtra("style", style); intent.putExtra("style", style);
intent.putExtra("bucket", bucket); intent.putExtra("bucket", bucket);
intent.putExtra("isfolder", isfolder);
startActivity(intent); startActivity(intent);
} }
} }

View file

@ -5,6 +5,10 @@
android:id="@+id/upload_file" android:id="@+id/upload_file"
android:title="@string/upload_file_here" /> android:title="@string/upload_file_here" />
<item
android:id="@+id/download_folder"
android:title="@string/download_folder" />
<item <item
android:id="@+id/info" android:id="@+id/info"
android:title="@string/object_info" /> android:title="@string/object_info" />

View file

@ -107,4 +107,6 @@
<string name="cors_error">No se pudo cambiar la política CORS</string> <string name="cors_error">No se pudo cambiar la política CORS</string>
<string name="cors_ok">Política CORS cambiada exitosamente</string> <string name="cors_ok">Política CORS cambiada exitosamente</string>
<string name="download_bucket">Descargar bucket</string> <string name="download_bucket">Descargar bucket</string>
<string name="download_folder">Descargar carpeta</string>
<string name="batch_download_success">Archivos descargados exitosamente</string>
</resources> </resources>

View file

@ -27,8 +27,10 @@
<string name="file_external">Open in</string> <string name="file_external">Open in</string>
<string name="download_file">Download file</string> <string name="download_file">Download file</string>
<string name="download_bucket">Download bucket</string> <string name="download_bucket">Download bucket</string>
<string name="download_folder">Download folder</string>
<string name="cancel_download">Cancel download</string> <string name="cancel_download">Cancel download</string>
<string name="download_success">File downloaded successfully</string> <string name="download_success">File downloaded successfully</string>
<string name="batch_download_success">Files downloaded successfully</string>
<string name="upload_file_tobucket">Upload file to this bucket</string> <string name="upload_file_tobucket">Upload file to this bucket</string>
<string name="upload_folder_tobucket">Upload folder to this bucket</string> <string name="upload_folder_tobucket">Upload folder to this bucket</string>
<string name="feature_not_supported">Your device is not compatible with this feature</string> <string name="feature_not_supported">Your device is not compatible with this feature</string>