Fix upload mms again

This commit is contained in:
lionel 2022-03-25 16:26:37 +01:00
parent 6a1ed20e07
commit 6a460b2952

View File

@ -28,6 +28,8 @@ public class UploadFile extends Transfer {
public Uri uri;
public String type;
public UploadFile() {
this.id = View.generateViewId();
instances.add(this);
@ -44,9 +46,19 @@ public class UploadFile extends Transfer {
Cursor cursor = activity.getContentResolver().query(uri, null, null, null, null);
cursor.moveToFirst();
file.name = cursor.getString(cursor.getColumnIndex(OpenableColumns.DISPLAY_NAME));
file.size = cursor.getLong(cursor.getColumnIndex(OpenableColumns.SIZE));
file.type = activity.getContentResolver().getType(uri);
int col_name = cursor.getColumnIndex(OpenableColumns.DISPLAY_NAME);
if (col_name != -1)
file.name = cursor.getString(col_name);
if(file.name == null)
file.name = file.type.split("/")[0] + "_" + new SimpleDateFormat("yyyyMMdd_HHmmss").format(new Date()) + "." + file.type.split("/")[1];
int col_size = cursor.getColumnIndex(OpenableColumns.SIZE);
if (col_name != -1) {
file.size = cursor.getLong(col_size);
file.sizeSI = Transfer.humanReadableByteCountBin(file.size);
}
file.AddTransfer();
}
@ -116,15 +128,7 @@ public class UploadFile extends Transfer {
Cursor cursor = activity.getContentResolver().query(uri, null, null, null, null);
cursor.moveToFirst();
String type = activity.getContentResolver().getType(uri);
String fileName = null;
int col_name = cursor.getColumnIndex(OpenableColumns.DISPLAY_NAME);
if (col_name != -1)
fileName = cursor.getString(col_name);
if(fileName == null)
fileName = type.split("/")[0] + "_" + new SimpleDateFormat("yyyyMMdd_HHmmss").format(new Date()) + "." + type.split("/")[1];
String fileNameUTF8 = new String(fileName.getBytes(), StandardCharsets.ISO_8859_1);
String fileNameUTF8 = new String(name.getBytes(), StandardCharsets.ISO_8859_1);
url = new URL(protocol, host, port, root + "/upload.php");
@ -152,6 +156,7 @@ public class UploadFile extends Transfer {
InputStream in = activity.getContentResolver().openInputStream(uri);
size = in.available();
sizeSI = Transfer.humanReadableByteCountBin(size);
while ((bufferLength = in.read(buffer)) > 0) {
request.write(buffer, 0, bufferLength);
@ -168,7 +173,7 @@ public class UploadFile extends Transfer {
int responseCode = conn.getResponseCode();
if (responseCode == HttpURLConnection.HTTP_OK) {
message = "File " + fileName + " successful upload";
message = "File " + name + " successful upload";
state = Transfer.STATE_SUCCESS;
progressEnd();
}