private Object uploadFileHelper(Object[] params, final File tempFile) { // Create listener for tracking upload progress in the notification if (mClient instanceof XMLRPCClient) { XMLRPCClient xmlrpcClient = (XMLRPCClient) mClient; xmlrpcClient.setOnBytesUploadedListener( new XMLRPCClient.OnBytesUploadedListener() { @Override public void onBytesUploaded(long uploadedBytes) { if (tempFile.length() == 0) { return; } float percentage = (uploadedBytes * 100) / tempFile.length(); mPostUploadNotifier.updateNotificationProgress(percentage); } }); } try { return mClient.call(ApiHelper.Methods.UPLOAD_FILE, params, tempFile); } catch (XMLRPCException e) { AppLog.e(T.API, e); mErrorMessage = mContext.getResources().getString(R.string.error_media_upload) + ": " + e.getMessage(); return null; } catch (IOException e) { AppLog.e(T.API, e); mErrorMessage = mContext.getResources().getString(R.string.error_media_upload) + ": " + e.getMessage(); return null; } catch (XmlPullParserException e) { AppLog.e(T.API, e); mErrorMessage = mContext.getResources().getString(R.string.error_media_upload) + ": " + e.getMessage(); return null; } finally { // remove the temporary upload file now that we're done with it if (tempFile != null && tempFile.exists()) { tempFile.delete(); } } }