file list implemented

This commit is contained in:
Page Asgardius 2022-12-30 18:44:42 -07:00
parent 69dacae861
commit 99049977c1
3 changed files with 40 additions and 10 deletions

View file

@ -65,6 +65,7 @@ public class Uploader extends AppCompatActivity {
Thread uploadFile, uploadProgress; Thread uploadFile, uploadProgress;
boolean style, isfolder; boolean style, isfolder;
boolean started = false; boolean started = false;
boolean cancel = false;
long transfered = 0; long transfered = 0;
private static final long MAX_SINGLE_PART_UPLOAD_BYTES = 5 * 1024 * 1024; private static final long MAX_SINGLE_PART_UPLOAD_BYTES = 5 * 1024 * 1024;
private WifiManager.WifiLock mWifiLock; private WifiManager.WifiLock mWifiLock;
@ -107,6 +108,7 @@ public class Uploader extends AppCompatActivity {
//buttonaction //buttonaction
if (started) { if (started) {
started = false; started = false;
cancel = true;
uploadFile.interrupt(); uploadFile.interrupt();
//simpleProgressBar.setVisibility(View.INVISIBLE); //simpleProgressBar.setVisibility(View.INVISIBLE);
} else { } else {
@ -149,22 +151,36 @@ public class Uploader extends AppCompatActivity {
for (int i = 0; i < filelist.length; i++) { for (int i = 0; i < filelist.length; i++) {
filepath.add(filelist[i].getName()); filepath.add(filelist[i].getName());
if(filelist[i].isDirectory()) { if(filelist[i].isDirectory()) {
//Nothing for now
treelevel++; treelevel++;
fileindex.add(0); fileindex.add(0);
document = filelist[i]; document = filelist[i];
filelist = document.listFiles(); filelist = document.listFiles();
while (treelevel >= 1 && fileindex.get(treelevel) < filelist.length) { while (treelevel >= 1 && fileindex.get(treelevel) < filelist.length) {
filepath.add(filelist[fileindex.get(treelevel)].getName()); filepath.add(filelist[fileindex.get(treelevel)].getName());
if (filelist[fileindex.get(treelevel)].isDirectory()) {
treelevel++;
fileindex.add(0);
document = filelist[i];
filelist = document.listFiles();
} else {
System.out.println(String.join("/", filepath)); System.out.println(String.join("/", filepath));
filepath.remove(treelevel);
if(filelist[fileindex.get(treelevel)].length()%MAX_SINGLE_PART_UPLOAD_BYTES == 0) { if(filelist[fileindex.get(treelevel)].length()%MAX_SINGLE_PART_UPLOAD_BYTES == 0) {
System.out.println((filelist[fileindex.get(treelevel)].length()/MAX_SINGLE_PART_UPLOAD_BYTES)+" parts"); System.out.println((filelist[fileindex.get(treelevel)].length()/MAX_SINGLE_PART_UPLOAD_BYTES)+" parts");
} else { } else {
System.out.println(((filelist[fileindex.get(treelevel)].length()/MAX_SINGLE_PART_UPLOAD_BYTES)+1)+" parts"); System.out.println(((filelist[fileindex.get(treelevel)].length()/MAX_SINGLE_PART_UPLOAD_BYTES)+1)+" parts");
} }
fileindex.set(treelevel, fileindex.get(treelevel)+1);
}
if(fileindex.get(treelevel) == filelist.length) {
fileindex.remove(treelevel);
document = document.getParentFile();
filelist = document.listFiles();
treelevel--;
filepath.remove(treelevel); filepath.remove(treelevel);
fileindex.set(treelevel, fileindex.get(treelevel)+1); fileindex.set(treelevel, fileindex.get(treelevel)+1);
} }
}
document = document.getParentFile(); document = document.getParentFile();
filelist = document.listFiles(); filelist = document.listFiles();
treelevel--; treelevel--;
@ -182,7 +198,11 @@ public class Uploader extends AppCompatActivity {
} }
} else { } else {
ufile = readContentToFile(fileuri); ufile = readContentToFile(fileuri);
filesize = ufile.length(); if(ufile.length()%MAX_SINGLE_PART_UPLOAD_BYTES == 0) {
filesize = ufile.length()/MAX_SINGLE_PART_UPLOAD_BYTES;
} else {
filesize = (ufile.length()/MAX_SINGLE_PART_UPLOAD_BYTES)+1;
}
//PutObjectRequest request = new PutObjectRequest(bucket, fkey, ufile); //PutObjectRequest request = new PutObjectRequest(bucket, fkey, ufile);
//upload = s3client.putObject(request); //upload = s3client.putObject(request);
putS3Object(bucket, fprefix.getText().toString(), ufile); putS3Object(bucket, fprefix.getText().toString(), ufile);
@ -234,7 +254,12 @@ public class Uploader extends AppCompatActivity {
started = false; started = false;
//simpleProgressBar.setVisibility(View.INVISIBLE); //simpleProgressBar.setVisibility(View.INVISIBLE);
//fileUpload.setEnabled(true); //fileUpload.setEnabled(true);
fileUpload.setText(getResources().getString(R.string.retry)); if (cancel) {
fileUpload.setText(getResources().getString(R.string.upload_canceled));
} else {
fileUpload.setText(getResources().getString(R.string.upload_failed));
}
fileUpload.setEnabled(false);
//Toast.makeText(getApplicationContext(),getResources().getString(R.string.media_list_fail), Toast.LENGTH_SHORT).show(); //Toast.makeText(getApplicationContext(),getResources().getString(R.string.media_list_fail), Toast.LENGTH_SHORT).show();
} }
}); });
@ -395,6 +420,7 @@ public class Uploader extends AppCompatActivity {
PutObjectRequest request = new PutObjectRequest(bucket, objectKey, file); PutObjectRequest request = new PutObjectRequest(bucket, objectKey, file);
PutObjectResult result = s3client.putObject(request); PutObjectResult result = s3client.putObject(request);
long bytesPushed = result.getMetadata().getContentLength(); long bytesPushed = result.getMetadata().getContentLength();
transfered++;
//LOGGER.info("Pushed {} bytes to s3://{}/{}", bytesPushed, bucket, objectKey); //LOGGER.info("Pushed {} bytes to s3://{}/{}", bytesPushed, bucket, objectKey);
} }
@ -429,7 +455,7 @@ public class Uploader extends AppCompatActivity {
partETags.add(uploadResult.getPartETag()); partETags.add(uploadResult.getPartETag());
fileOffset += partSize; fileOffset += partSize;
transfered = fileOffset; transfered++;
} }
// Complete the multipart upload. // Complete the multipart upload.

View file

@ -27,6 +27,7 @@
<string name="cancel_upload">Cancelar subida</string> <string name="cancel_upload">Cancelar subida</string>
<string name="retry">Reintentar</string> <string name="retry">Reintentar</string>
<string name="download_failed">Descarga fallida</string> <string name="download_failed">Descarga fallida</string>
<string name="upload_failed">Subida fallida</string>
<string name="success">Éxito</string> <string name="success">Éxito</string>
<string name="create_bucket">Crear nuevo bucket</string> <string name="create_bucket">Crear nuevo bucket</string>
<string name="create_bucket_success">Bucket creado exitosamente</string> <string name="create_bucket_success">Bucket creado exitosamente</string>
@ -86,6 +87,7 @@
<string name="file_count">Archivos</string> <string name="file_count">Archivos</string>
<string name="null_expiration_date">Debe establecer una fecha de expiración para compartir archivos</string> <string name="null_expiration_date">Debe establecer una fecha de expiración para compartir archivos</string>
<string name="download_canceled">Descarga cancelada</string> <string name="download_canceled">Descarga cancelada</string>
<string name="upload_canceled">Subida cancelada</string>
<string name="settings">Ajustes</string> <string name="settings">Ajustes</string>
<string name="save_settings">Guardar ajustes</string> <string name="save_settings">Guardar ajustes</string>
<string name="videocache">Tamaño máximo de cache multimedia (en MiB)</string> <string name="videocache">Tamaño máximo de cache multimedia (en MiB)</string>

View file

@ -44,6 +44,8 @@
<string name="retry">Retry</string> <string name="retry">Retry</string>
<string name="download_failed">Download failed</string> <string name="download_failed">Download failed</string>
<string name="download_canceled">Download canceled</string> <string name="download_canceled">Download canceled</string>
<string name="upload_failed">Upload failed</string>
<string name="upload_canceled">Upload canceled</string>
<string name="success">Success</string> <string name="success">Success</string>
<string name="object_info">Properties</string> <string name="object_info">Properties</string>
<string name="file_size">File Size</string> <string name="file_size">File Size</string>