Skip to content

Commit

Permalink
Merge pull request #760 from haiwen/fix_get_file_path_error
Browse files Browse the repository at this point in the history
fix get file path from uri error
  • Loading branch information
freeplant authored Sep 25, 2018
2 parents fd759f5 + 6d999ff commit 0587eeb
Show file tree
Hide file tree
Showing 3 changed files with 31 additions and 162 deletions.
4 changes: 2 additions & 2 deletions app/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -7,8 +7,8 @@ android {
applicationId 'com.seafile.seadroid2'
minSdkVersion rootProject.ext.minSdkVersion
targetSdkVersion rootProject.ext.targetSdkVersion
versionCode 82
versionName "2.2.7"
versionCode 83
versionName "2.2.8"
multiDexEnabled true
resValue "string", "authorities", applicationId + '.cameraupload.provider'
resValue "string", "account_type", "com.seafile.seadroid2.account.api2"
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -91,15 +91,18 @@
import com.seafile.seadroid2.ui.fragment.ReposFragment;
import com.seafile.seadroid2.ui.fragment.StarredFragment;
import com.seafile.seadroid2.util.ConcurrentAsyncTask;
import com.seafile.seadroid2.util.UriFilePath;
import com.seafile.seadroid2.util.Utils;
import com.seafile.seadroid2.util.UtilsJellyBean;
import com.viewpagerindicator.IconPagerAdapter;

import org.apache.commons.io.IOUtils;
import org.json.JSONException;

import java.io.File;
import java.io.FileOutputStream;
import java.io.IOException;
import java.io.InputStream;
import java.io.OutputStream;
import java.text.SimpleDateFormat;
import java.util.ArrayList;
import java.util.Date;
Expand Down Expand Up @@ -1381,37 +1384,31 @@ protected File[] doInBackground(Uri... uriList) {
List<File> fileList = new ArrayList<File>();
for (Uri uri: uriList) {
// Log.d(DEBUG_TAG, "Uploading file from uri: " + uri);
// ============ copy file to seafile dir ===================
// InputStream in = null;
// OutputStream out = null;
//
// try {
// File tempDir = DataManager.createTempDir();
// File tempFile = new File(tempDir, Utils.getFilenamefromUri(BrowserActivity.this, uri));
//
// if (!tempFile.createNewFile()) {
// throw new RuntimeException("could not create temporary file");
// }
//
// in = getContentResolver().openInputStream(uri);
// out = new FileOutputStream(tempFile);
// IOUtils.copy(in, out);
//
// fileList.add(tempFile);
//
// } catch (IOException e) {
// Log.d(DEBUG_TAG, "Could not open requested document", e);
// } catch (RuntimeException e) {
// Log.d(DEBUG_TAG, "Could not open requested document", e);
// } finally {
// IOUtils.closeQuietly(in);
// IOUtils.closeQuietly(out);
// }
// =============== new idea,file upload no copy seafile dir ================
String path = UriFilePath.getFileAbsolutePath(BrowserActivity.this, uri);
File tempFile = new File(path);
fileList.add(tempFile);
// =============== new idea,file upload no copy seafile dir ================
InputStream in = null;
OutputStream out = null;

try {
File tempDir = DataManager.createTempDir();
File tempFile = new File(tempDir, Utils.getFilenamefromUri(BrowserActivity.this, uri));

if (!tempFile.createNewFile()) {
throw new RuntimeException("could not create temporary file");
}

in = getContentResolver().openInputStream(uri);
out = new FileOutputStream(tempFile);
IOUtils.copy(in, out);

fileList.add(tempFile);

} catch (IOException e) {
Log.d(DEBUG_TAG, "Could not open requested document", e);
} catch (RuntimeException e) {
Log.d(DEBUG_TAG, "Could not open requested document", e);
} finally {
IOUtils.closeQuietly(in);
IOUtils.closeQuietly(out);
}
}
return fileList.toArray(new File[]{});
}
Expand Down
128 changes: 0 additions & 128 deletions app/src/main/java/com/seafile/seadroid2/util/UriFilePath.java

This file was deleted.

0 comments on commit 0587eeb

Please sign in to comment.