fixes an issue where local files couldn't be picked | refactors temp cloud file name

This commit is contained in:
Miguel Ruivo 2018-08-16 15:43:42 +01:00
parent d9051223b3
commit 6ec2041e53
2 changed files with 11 additions and 21 deletions

View File

@ -25,7 +25,7 @@
</value> </value>
</option> </option>
</component> </component>
<component name="ProjectRootManager" version="2" languageLevel="JDK_1_7" project-jdk-name="1.8" project-jdk-type="JavaSDK"> <component name="ProjectRootManager" version="2" languageLevel="JDK_1_8" project-jdk-name="1.8" project-jdk-type="JavaSDK">
<output url="file://$PROJECT_DIR$/build/classes" /> <output url="file://$PROJECT_DIR$/build/classes" />
</component> </component>
<component name="ProjectType"> <component name="ProjectType">

View File

@ -48,23 +48,23 @@ public class FilePickerPlugin implements MethodCallHandler {
Uri uri = data.getData(); Uri uri = data.getData();
Log.i(TAG, "URI:" +data.getData().toString()); Log.i(TAG, "URI:" +data.getData().toString());
String fullPath = Commons.getPath(uri, instance.context()); String fullPath = Commons.getPath(uri, instance.context());
String cloudFile = null; String cloudFile = null;
if(fullPath == null) if(fullPath == null)
{ {
FileOutputStream fos = null; FileOutputStream fos = null;
cloudFile = instance.activeContext().getCacheDir()+data.getData().toString().split("/")[data.getData().toString().split("/").length-1]; cloudFile = instance.activeContext().getCacheDir().getAbsolutePath() + "/Document";
try { try {
fos = new FileOutputStream(cloudFile); fos = new FileOutputStream(cloudFile);
try { try{
BufferedOutputStream out = new BufferedOutputStream(fos); BufferedOutputStream out = new BufferedOutputStream(fos);
InputStream in = instance.activeContext().getContentResolver().openInputStream(uri); InputStream in = instance.activeContext().getContentResolver().openInputStream(uri);
byte[] buffer = new byte[8192]; byte[] buffer = new byte[8192];
int len = 0; int len = 0;
while ((len = in.read(buffer)) >= 0) { while ((len = in.read(buffer)) >= 0){
out.write(buffer, 0, len); out.write(buffer, 0, len);
} }
@ -76,22 +76,12 @@ public class FilePickerPlugin implements MethodCallHandler {
} catch (Exception e) { } catch (Exception e) {
e.printStackTrace(); e.printStackTrace();
} }
}
Log.i(TAG, "FilePath:" + cloudFile);
fullPath = cloudFile;
File file = new File(cloudFile);
if (Integer.parseInt(String.valueOf(file.length() / 1024)) > 1024) {
InputStream imageStream = null;
try { Log.i(TAG, "Loaded file from cloud created on:" + cloudFile);
imageStream = instance.activeContext().getContentResolver().openInputStream(uri); fullPath = cloudFile;
} catch (FileNotFoundException e) {
e.printStackTrace();
}
Log.i(TAG, "FilePath:" + cloudFile);
} }
Log.i(TAG, "FilePath:" + fullPath);
Log.i(TAG, "Absolute file path:" + fullPath);
result.success(fullPath); result.success(fullPath);
} }