X-Git-Url: http://git.linex4red.de/pub/Android/ownCloud.git/blobdiff_plain/fd7a940deefe91a8e547d99a2054370510b68090..e901b609baa4dd5f681e2a5257c9e504997e3377:/src/com/owncloud/android/files/services/FileUploader.java diff --git a/src/com/owncloud/android/files/services/FileUploader.java b/src/com/owncloud/android/files/services/FileUploader.java index ad2a2cbe..04804402 100644 --- a/src/com/owncloud/android/files/services/FileUploader.java +++ b/src/com/owncloud/android/files/services/FileUploader.java @@ -73,6 +73,7 @@ import com.owncloud.android.operations.common.SyncOperation; import com.owncloud.android.ui.activity.FileActivity; import com.owncloud.android.ui.activity.FileDisplayActivity; import com.owncloud.android.utils.ErrorMessageAdapter; +import com.owncloud.android.utils.UriUtils; @@ -120,6 +121,9 @@ public class FileUploader extends Service implements OnDatatransferProgressListe private NotificationCompat.Builder mNotificationBuilder; private int mLastPercent; + private static final String MIME_TYPE_PDF = "application/pdf"; + private static final String FILE_EXTENSION_PDF = ".pdf"; + public static String getUploadFinishMessage() { return FileUploader.class.getName().toString() + UPLOAD_FINISH_MESSAGE; @@ -646,18 +650,6 @@ public class FileUploader extends Service implements OnDatatransferProgressListe private OCFile obtainNewOCFileToUpload(String remotePath, String localPath, String mimeType, FileDataStorageManager storageManager) { - OCFile newFile = new OCFile(remotePath); - newFile.setStoragePath(localPath); - newFile.setLastSyncDateForProperties(0); - newFile.setLastSyncDateForData(0); - - // size - if (localPath != null && localPath.length() > 0) { - File localFile = new File(localPath); - newFile.setFileLength(localFile.length()); - newFile.setLastSyncDateForData(localFile.lastModified()); - } // don't worry about not assigning size, the problems with localPath - // are checked when the UploadFileOperation instance is created // MIME type if (mimeType == null || mimeType.length() <= 0) { @@ -671,6 +663,25 @@ public class FileUploader extends Service implements OnDatatransferProgressListe if (mimeType == null) { mimeType = "application/octet-stream"; } + + if (isPdfFileFromContentProviderWithoutExtension(localPath, mimeType)){ + remotePath += FILE_EXTENSION_PDF; + } + + OCFile newFile = new OCFile(remotePath); + newFile.setStoragePath(localPath); + newFile.setLastSyncDateForProperties(0); + newFile.setLastSyncDateForData(0); + + // size + if (localPath != null && localPath.length() > 0) { + File localFile = new File(localPath); + newFile.setFileLength(localFile.length()); + newFile.setLastSyncDateForData(localFile.lastModified()); + } // don't worry about not assigning size, the problems with localPath + // are checked when the UploadFileOperation instance is created + + newFile.setMimetype(mimeType); return newFile; @@ -856,4 +867,17 @@ public class FileUploader extends Service implements OnDatatransferProgressListe sendStickyBroadcast(end); } + /** + * Checks if content provider, using the content:// scheme, returns a file with mime-type + * 'application/pdf' but file has not extension + * @param localPath + * @param mimeType + * @return true if is needed to add the pdf file extension to the file + */ + private boolean isPdfFileFromContentProviderWithoutExtension(String localPath, String mimeType) { + return localPath.startsWith(UriUtils.URI_CONTENT_SCHEME) && + mimeType.equals(MIME_TYPE_PDF) && + !localPath.endsWith(FILE_EXTENSION_PDF); + } + }