bug 638940 - File Upload: we should not change file names, paths and extensions r=dougt

This commit is contained in:
Brad Lassey 2011-06-01 20:40:38 -04:00
Родитель 57ccd1737f
Коммит fe59b91fa1
1 изменённых файлов: 29 добавлений и 7 удалений

Просмотреть файл

@ -59,6 +59,8 @@ import android.hardware.*;
import android.util.*;
import android.net.*;
import android.database.*;
import android.provider.*;
abstract public class GeckoApp
extends Activity
@ -654,13 +656,33 @@ abstract public class GeckoApp
try {
ContentResolver cr = getContentResolver();
Uri uri = data.getData();
String mimeType = cr.getType(uri);
String fileExt = "." +
GeckoAppShell.getExtensionFromMimeType(mimeType);
File file =
File.createTempFile("tmp_" +
(int)Math.floor(1000 * Math.random()),
fileExt, sGREDir);
Cursor cursor = GeckoApp.mAppContext.getContentResolver().query(
uri,
new String[] { OpenableColumns.DISPLAY_NAME },
null,
null,
null);
String name = null;
if (cursor != null) {
try {
if (cursor.moveToNext()) {
name = cursor.getString(0);
}
} finally {
cursor.close();
}
}
String fileName = "tmp_";
String fileExt = null;
int period;
if (name == null || (period = name.lastIndexOf('.')) == -1) {
String mimeType = cr.getType(uri);
fileExt = "." + GeckoAppShell.getExtensionFromMimeType(mimeType);
} else {
fileExt = name.substring(period);
fileName = name.substring(0, period);
}
File file = File.createTempFile(fileName, fileExt, sGREDir);
FileOutputStream fos = new FileOutputStream(file);
InputStream is = cr.openInputStream(uri);