batch download
This commit is contained in:
parent
a8b6a2d019
commit
c1342adcee
7 changed files with 71 additions and 9 deletions
|
@ -163,6 +163,10 @@ public class BucketSelect extends AppCompatActivity {
|
|||
//Toast.makeText(BucketSelect.this, getResources().getString(R.string.pending_feature), Toast.LENGTH_SHORT).show();
|
||||
upload(Name.get(position).toString());
|
||||
|
||||
} else if (menuItem.getTitle() == getResources().getString(R.string.download_bucket)) {
|
||||
//Toast.makeText(BucketSelect.this, getResources().getString(R.string.pending_feature), Toast.LENGTH_SHORT).show();
|
||||
download(Name.get(position).toString());
|
||||
|
||||
} else if (menuItem.getTitle() == getResources().getString(R.string.create_bucket)) {
|
||||
//upload();
|
||||
newBucket();
|
||||
|
@ -325,6 +329,20 @@ public class BucketSelect extends AppCompatActivity {
|
|||
startActivity(intent);
|
||||
}
|
||||
|
||||
private void download(String bucket) {
|
||||
|
||||
Intent intent = new Intent(this, Downloader.class);
|
||||
intent.putExtra("endpoint", endpoint);
|
||||
intent.putExtra("username", username);
|
||||
intent.putExtra("password", password);
|
||||
intent.putExtra("prefix", prefix);
|
||||
intent.putExtra("region", location);
|
||||
intent.putExtra("style", style);
|
||||
intent.putExtra("bucket", bucket);
|
||||
intent.putExtra("isfolder", true);
|
||||
startActivity(intent);
|
||||
}
|
||||
|
||||
private void corsConfig(String bucket) {
|
||||
Intent intent = new Intent(this, CorsConfig.class);
|
||||
intent.putExtra("endpoint", endpoint);
|
||||
|
|
|
@ -26,11 +26,16 @@ 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.ListObjectsRequest;
|
||||
import com.amazonaws.services.s3.model.ObjectListing;
|
||||
import com.amazonaws.services.s3.model.S3Object;
|
||||
import com.amazonaws.services.s3.model.S3ObjectSummary;
|
||||
|
||||
import java.io.IOException;
|
||||
import java.io.InputStream;
|
||||
import java.io.OutputStream;
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
|
||||
public class Downloader extends AppCompatActivity {
|
||||
String username, password, endpoint, bucket, filename, prefix, location;
|
||||
|
@ -40,6 +45,7 @@ public class Downloader extends AppCompatActivity {
|
|||
AWSCredentials myCredentials;
|
||||
AmazonS3 s3client;
|
||||
ProgressBar simpleProgressBar;
|
||||
ListObjectsRequest orequest;
|
||||
Intent intent;
|
||||
Button fileDownload;
|
||||
Thread downloadFile, downloadProgress;
|
||||
|
@ -47,9 +53,9 @@ public class Downloader extends AppCompatActivity {
|
|||
DocumentFile document;
|
||||
boolean started = false;
|
||||
boolean cancel = false;
|
||||
boolean isfolder = false;
|
||||
boolean style;
|
||||
boolean style, isfolder;
|
||||
long filesize = 0;
|
||||
long objectsize;
|
||||
long transfered = 0;
|
||||
private WifiManager.WifiLock mWifiLock;
|
||||
private PowerManager.WakeLock mWakeLock;
|
||||
|
@ -70,6 +76,7 @@ public class Downloader extends AppCompatActivity {
|
|||
bucket = getIntent().getStringExtra("bucket");
|
||||
location = getIntent().getStringExtra("region");
|
||||
style = getIntent().getBooleanExtra("style", false);
|
||||
isfolder = getIntent().getBooleanExtra("isfolder", false);
|
||||
prefix = getIntent().getStringExtra("prefix");
|
||||
simpleProgressBar = (ProgressBar) findViewById(R.id.simpleProgressBar);
|
||||
fileDownload = (Button)findViewById(R.id.filedownload);
|
||||
|
@ -121,12 +128,44 @@ public class Downloader extends AppCompatActivity {
|
|||
//s3client.createBucket(bucket, location);
|
||||
//System.out.println(fkey);
|
||||
document = DocumentFile.fromTreeUri(getApplicationContext(), fileuri);
|
||||
object = s3client.getObject(bucket, prefix+filename);
|
||||
filesize = (object.getObjectMetadata().getContentLength())/1024;
|
||||
if (isfolder) {
|
||||
filepath = document.createFile(null, filename).getUri();
|
||||
writeContentToFile(filepath, object);
|
||||
if (object == null) {
|
||||
orequest = new ListObjectsRequest().withBucketName(bucket).withMaxKeys(1000);
|
||||
}
|
||||
ArrayList<String> objectlist = new ArrayList<String>();
|
||||
ObjectListing result = s3client.listObjects(orequest);
|
||||
List<S3ObjectSummary> objects = result.getObjectSummaries();
|
||||
for (S3ObjectSummary os : objects) {
|
||||
objectlist.add(os.getKey());
|
||||
objectsize = os.getSize();
|
||||
if (objectsize%1024 == 0) {
|
||||
filesize = filesize+(objectsize/1024);
|
||||
} else {
|
||||
filesize = filesize+(objectsize/1024)+1;
|
||||
}
|
||||
}
|
||||
while (result.isTruncated()) {
|
||||
result = s3client.listNextBatchOfObjects (result);
|
||||
objects = result.getObjectSummaries();
|
||||
for (S3ObjectSummary os : objects) {
|
||||
objectlist.add(os.getKey());
|
||||
objectsize = os.getSize();
|
||||
if (objectsize%1024 == 0) {
|
||||
filesize = filesize+(objectsize/1024);
|
||||
} else {
|
||||
filesize = filesize+(objectsize/1024)+1;
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
for (String os : objectlist) {
|
||||
object = s3client.getObject(bucket, os);
|
||||
filepath = document.createFile(null, os).getUri();
|
||||
writeContentToFile(filepath, object);
|
||||
}
|
||||
} else {
|
||||
object = s3client.getObject(bucket, prefix+filename);
|
||||
filesize = (object.getObjectMetadata().getContentLength())/1024;
|
||||
writeContentToFile(fileuri, object);
|
||||
}
|
||||
runOnUiThread(new Runnable() {
|
||||
|
|
|
@ -80,7 +80,7 @@ public class ObjectInfo extends AppCompatActivity {
|
|||
//Your code goes here
|
||||
if (object == null) {
|
||||
isobject = false;
|
||||
orequest = new ListObjectsRequest().withBucketName(bucket).withMaxKeys(8000);
|
||||
orequest = new ListObjectsRequest().withBucketName(bucket).withMaxKeys(1000);
|
||||
} else {
|
||||
isobject = true;
|
||||
if (object.endsWith("/")) {
|
||||
|
@ -88,7 +88,7 @@ public class ObjectInfo extends AppCompatActivity {
|
|||
} else {
|
||||
isfolder = false;
|
||||
}
|
||||
orequest = new ListObjectsRequest().withBucketName(bucket).withPrefix(object).withMaxKeys(8000);
|
||||
orequest = new ListObjectsRequest().withBucketName(bucket).withPrefix(object).withMaxKeys(1000);
|
||||
}
|
||||
ObjectListing result = s3client.listObjects(orequest);
|
||||
List<S3ObjectSummary> objects = result.getObjectSummaries();
|
||||
|
|
|
@ -655,7 +655,6 @@ public class ObjectSelect extends AppCompatActivity {
|
|||
intent.putExtra("endpoint", endpoint);
|
||||
intent.putExtra("username", username);
|
||||
intent.putExtra("password", password);
|
||||
intent.putExtra("prefix", prefix);
|
||||
intent.putExtra("region", location);
|
||||
intent.putExtra("style", style);
|
||||
intent.putExtra("bucket", bucket);
|
||||
|
|
|
@ -5,6 +5,10 @@
|
|||
android:id="@+id/upload_file"
|
||||
android:title="@string/upload_file_tobucket" />
|
||||
|
||||
<item
|
||||
android:id="@+id/download_bucket"
|
||||
android:title="@string/download_bucket" />
|
||||
|
||||
<item
|
||||
android:id="@+id/newbucket"
|
||||
android:title="@string/create_bucket" />
|
||||
|
|
|
@ -106,4 +106,5 @@
|
|||
<string name="delete_cors">Eliminar 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="download_bucket">Descargar bucket</string>
|
||||
</resources>
|
|
@ -26,6 +26,7 @@
|
|||
<string name="file_share">Share file</string>
|
||||
<string name="file_external">Open in</string>
|
||||
<string name="download_file">Download file</string>
|
||||
<string name="download_bucket">Download bucket</string>
|
||||
<string name="cancel_download">Cancel download</string>
|
||||
<string name="download_success">File downloaded successfully</string>
|
||||
<string name="upload_file_tobucket">Upload file to this bucket</string>
|
||||
|
|
Loading…
Reference in a new issue