private static final String TAG = UploadFileOperation.class.getSimpleName();
+ private static final String URI_CONTENT_SCHEME = "content://";
+ private static final String MIME_TYPE_PDF = "application/pdf";
+ private static final String FILE_EXTENSION_PDF = ".pdf";
+
private Account mAccount;
private OCFile mFile;
private OCFile mOldFile;
} else {
String temporalPath = FileStorageUtils.getTemporalPath(mAccount.name) + mFile.getRemotePath();
+
+ if (isPdfFileFromContentProviderWithoutExtension()){
+ temporalPath += FILE_EXTENSION_PDF;
+ mFile.setRemotePath(mFile.getRemotePath() + FILE_EXTENSION_PDF);
+ }
+
mFile.setStoragePath(temporalPath);
temporalFile = new File(temporalPath);
try {
- if (mOriginalStoragePath.startsWith("content://")) {
+ // In case document provider schema as 'content://'
+ if (mOriginalStoragePath.startsWith(URI_CONTENT_SCHEME)) {
Uri uri = Uri.parse(mOriginalStoragePath);
public void cancel() {
mUploadOperation.cancel();
}
+
+ /**
+ * Checks if content provider, using the content:// scheme, returns a file with mime-type
+ * 'application/pdf' but file has not extension
+ * @return true if is needed to add the pdf file extension to the file
+ */
+ private boolean isPdfFileFromContentProviderWithoutExtension() {
+ return mOriginalStoragePath.startsWith(URI_CONTENT_SCHEME) &&
+ mFile.getMimetype().equals(MIME_TYPE_PDF) &&
+ !mFile.getFileName().endsWith(FILE_EXTENSION_PDF);
+ }
}
private OCFile mWaitingToSend;
- private static final String URI_TYPE_OF_CONTENT_PROVIDER = "content://";
+ private static final String URI_CONTENT_SCHEME = "content://";
@Override
protected void onCreate(Bundle savedInstanceState) {
private void requestSimpleUpload(Intent data, int resultCode) {
String filepath = null;
+ String mimeType = null;
+
+ Uri selectedImageUri = data.getData();
+
try {
- Uri selectedImageUri = data.getData();
+ mimeType = getContentResolver().getType(selectedImageUri);
String filemanagerstring = selectedImageUri.getPath();
String selectedImagePath = getPath(selectedImageUri);
if (!remotepath.endsWith(OCFile.PATH_SEPARATOR))
remotepath += OCFile.PATH_SEPARATOR;
- if (filepath.startsWith(URI_TYPE_OF_CONTENT_PROVIDER)) {
- // The query, since it only applies to a single document, will only return
- // one row.
+ if (filepath.startsWith(URI_CONTENT_SCHEME)) {
+
Cursor cursor = MainApp.getAppContext().getContentResolver()
.query(Uri.parse(filepath), null, null, null, null, null);
if (cursor != null && cursor.moveToFirst()) {
String displayName = cursor.getString(
cursor.getColumnIndex(OpenableColumns.DISPLAY_NAME));
- Log.i(TAG, "Display Name: " + displayName);
+ Log.i(TAG, "Display Name: " + displayName + "; mimeType: " + mimeType);
+
+ remotepath += displayName + getComposedFileExtension(filepath);
- remotepath += displayName;
}
} finally {
cursor.close();
i.putExtra(FileUploader.KEY_LOCAL_FILE, filepath);
i.putExtra(FileUploader.KEY_REMOTE_FILE, remotepath);
+ i.putExtra(FileUploader.KEY_MIME_TYPE, mimeType);
i.putExtra(FileUploader.KEY_UPLOAD_TYPE, FileUploader.UPLOAD_SINGLE_FILE);
if (resultCode == UploadFilesActivity.RESULT_OK_AND_MOVE)
i.putExtra(FileUploader.KEY_LOCAL_BEHAVIOUR, FileUploader.LOCAL_BEHAVIOUR_MOVE);
* @return Whether the Uri is from a content provider as kind "content://..."
*/
public static boolean isContentDocument(Uri uri) {
- return uri.toString().startsWith(URI_TYPE_OF_CONTENT_PROVIDER);
+ return uri.toString().startsWith(URI_CONTENT_SCHEME);
}
/**
private void sortByName(boolean ascending){
getListOfFilesFragment().sortByName(ascending);
}
+
+ /**
+ * Get the file extension if it is on path as type "content://.../DocInfo.doc"
+ * @param filepath: Content Uri converted to string format
+ * @return String: fileExtension (type '.pdf'). Empty if no extension
+ */
+ private String getComposedFileExtension(String filepath) {
+ String fileExtension = "";
+ String fileNameInContentUri = filepath.substring(filepath.lastIndexOf("/"));
+
+ // Check if extension is included in uri
+ int pos = fileNameInContentUri.lastIndexOf('.');
+ if (pos >= 0) {
+ fileExtension = fileNameInContentUri.substring(pos);
+ }
+ return fileExtension;
+ }
}