folder download
This commit is contained in:
parent
c1342adcee
commit
44c28dc748
5 changed files with 30 additions and 7 deletions
|
@ -127,10 +127,12 @@ public class Downloader extends AppCompatActivity {
|
|||
//Your code goes here
|
||||
//s3client.createBucket(bucket, location);
|
||||
//System.out.println(fkey);
|
||||
document = DocumentFile.fromTreeUri(getApplicationContext(), fileuri);
|
||||
if (isfolder) {
|
||||
if (object == null) {
|
||||
document = DocumentFile.fromTreeUri(getApplicationContext(), fileuri);
|
||||
if (prefix == null) {
|
||||
orequest = new ListObjectsRequest().withBucketName(bucket).withMaxKeys(1000);
|
||||
} else {
|
||||
orequest = new ListObjectsRequest().withBucketName(bucket).withPrefix(prefix).withMaxKeys(1000);
|
||||
}
|
||||
ArrayList<String> objectlist = new ArrayList<String>();
|
||||
ObjectListing result = s3client.listObjects(orequest);
|
||||
|
@ -160,7 +162,7 @@ public class Downloader extends AppCompatActivity {
|
|||
}
|
||||
for (String os : objectlist) {
|
||||
object = s3client.getObject(bucket, os);
|
||||
filepath = document.createFile(null, os).getUri();
|
||||
filepath = document.createFile(null, os.replace(prefix, "")).getUri();
|
||||
writeContentToFile(filepath, object);
|
||||
}
|
||||
} else {
|
||||
|
@ -182,7 +184,11 @@ public class Downloader extends AppCompatActivity {
|
|||
//System.out.println("WakeLock released");
|
||||
}
|
||||
simpleProgressBar.setProgress(100);
|
||||
fileDownload.setText(getResources().getString(R.string.download_success));
|
||||
if (isfolder) {
|
||||
fileDownload.setText(getResources().getString(R.string.batch_download_success));
|
||||
} else {
|
||||
fileDownload.setText(getResources().getString(R.string.download_success));
|
||||
}
|
||||
fileDownload.setEnabled(false);
|
||||
//simpleProgressBar.setVisibility(View.INVISIBLE);
|
||||
}
|
||||
|
|
|
@ -394,6 +394,9 @@ public class ObjectSelect extends AppCompatActivity {
|
|||
if (menuItem.getTitle() == getResources().getString(R.string.upload_file_here)) {
|
||||
//Toast.makeText(ObjectSelect.this, getResources().getString(R.string.pending_feature), Toast.LENGTH_SHORT).show();
|
||||
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)) {
|
||||
objectInfo(prefix + Name.get(position).toString(), Name.get(position).toString());
|
||||
} 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();
|
||||
if (menuItem.getTitle() == getResources().getString(R.string.download_file)) {
|
||||
//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)) {
|
||||
//Toast.makeText(ObjectSelect.this, getResources().getString(R.string.pending_feature), Toast.LENGTH_SHORT).show();
|
||||
upload();
|
||||
|
@ -648,16 +651,22 @@ public class ObjectSelect extends AppCompatActivity {
|
|||
startActivity(intent);
|
||||
}
|
||||
|
||||
private void download(String filename) {
|
||||
private void download(String filename, boolean isfolder) {
|
||||
|
||||
Intent intent = new Intent(this, Downloader.class);
|
||||
intent.putExtra("filename", filename);
|
||||
if(isfolder) {
|
||||
intent.putExtra("prefix", prefix+filename);
|
||||
} else {
|
||||
intent.putExtra("prefix", prefix);
|
||||
intent.putExtra("filename", filename);
|
||||
}
|
||||
intent.putExtra("endpoint", endpoint);
|
||||
intent.putExtra("username", username);
|
||||
intent.putExtra("password", password);
|
||||
intent.putExtra("region", location);
|
||||
intent.putExtra("style", style);
|
||||
intent.putExtra("bucket", bucket);
|
||||
intent.putExtra("isfolder", isfolder);
|
||||
startActivity(intent);
|
||||
}
|
||||
}
|
|
@ -5,6 +5,10 @@
|
|||
android:id="@+id/upload_file"
|
||||
android:title="@string/upload_file_here" />
|
||||
|
||||
<item
|
||||
android:id="@+id/download_folder"
|
||||
android:title="@string/download_folder" />
|
||||
|
||||
<item
|
||||
android:id="@+id/info"
|
||||
android:title="@string/object_info" />
|
||||
|
|
|
@ -107,4 +107,6 @@
|
|||
<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="download_bucket">Descargar bucket</string>
|
||||
<string name="download_folder">Descargar carpeta</string>
|
||||
<string name="batch_download_success">Archivos descargados exitosamente</string>
|
||||
</resources>
|
|
@ -27,8 +27,10 @@
|
|||
<string name="file_external">Open in</string>
|
||||
<string name="download_file">Download file</string>
|
||||
<string name="download_bucket">Download bucket</string>
|
||||
<string name="download_folder">Download folder</string>
|
||||
<string name="cancel_download">Cancel download</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_folder_tobucket">Upload folder to this bucket</string>
|
||||
<string name="feature_not_supported">Your device is not compatible with this feature</string>
|
||||
|
|
Loading…
Reference in a new issue