+ newFile.setKeepInSync(forceOverwrite);
+
+ // size
+ if (localPath != null && localPath.length() > 0) {
+ File localFile = new File(localPath);
+ newFile.setFileLength(localFile.length());
+ } // 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) {
+ try {
+ mimeType = MimeTypeMap.getSingleton()
+ .getMimeTypeFromExtension(
+ remotePath.substring(remotePath.lastIndexOf('.') + 1));
+ } catch (IndexOutOfBoundsException e) {
+ Log.e(TAG, "Trying to find out MIME type of a file without extension: " + remotePath);
+ }
+ }
+ if (mimeType == null) {
+ mimeType = "application/octet-stream";
+ }
+ newFile.setMimetype(mimeType);
+
+ // parent dir
+ String parentPath = new File(remotePath).getParent();
+ parentPath = parentPath.endsWith("/")?parentPath:parentPath+"/" ;
+ OCFile parentDir = storageManager.getFileByPath(parentPath);
+ if (parentDir == null) {
+ throw new IllegalStateException("Can not upload a file to a non existing remote location: " + parentPath);
+ }
+ long parentDirId = parentDir.getFileId();