Upload Images to OwnCloud and NextCloud in Phimpme Android
As increasing the stack of account manager in Phimpme Android. We have now two new items OwnCloud and NextCloud to add. Both are open source storage services. Provides complete source code of their official apps and libraries on Github. You can check below
This requires a hosting server, where you can deploy it and access it through their web app and Mobile apps. I added a feature in Phimpme to upload images directly to the server right from the app using their android-library.
Steps (How I did in Phimpme)
Add library in Application gradle file
Firstly, to work with, we need to add the android-library they provide.
Check the new version from here and apply over it: https://github.com/nextcloud/android-library/releases
Login from Account Manager
As per our Phimpme app flow, User first connect itself from the account manager and then share image from app using these credentials. Added a new Login activity for OwnCloud and NextCloud both.
Saved credentials in Database
To use that further in android-library, I store the credentials in Realm database.
account.setServerUrl(data.getStringExtra(getString(R.string.server_url))); account.setUsername(data.getStringExtra(getString(R.string.auth_username))); account.setPassword(data.getStringExtra(getString(R.string.auth_password)));
Uploading image using library
As per the official guide of OwnCloud, used Created an object of OwnCloudClient. Set the username and password.
private OwnCloudClient mClient; mClient = OwnCloudClientFactory.createOwnCloudClient(serverUri, this, true); mClient.setCredentials( OwnCloudCredentialsFactory.newBasicCredentials( username, password ) );
Passed the image path which we are getting in the SharingActivity. Modified with adding the separator.
File fileToUpload = new File(saveFilePath); String remotePath = FileUtils.PATH_SEPARATOR + fileToUpload.getName();
Used the UploadRemoteOperation Class and just need to pass the path, mimeType and timeStamp. The library have already defined functions to execute the upload operations.
UploadRemoteFileOperation uploadOperation = new UploadRemoteFileOperation(fileToUpload.getAbsolutePath(), remotePath, mimeType, timeStamp); uploadOperation.execute(mClient, this, mHandler);
Setup Account using Docker and Digital Ocean
I have already a previous blog post on how to setup NextCloud or OwnCloud account on server using Digital Ocean and Docker.
- NextCloud Developer Mannual: https://docs.nextcloud.com/server/9/developer_manual/index.html
- OwnCloud Library installation: https://doc.owncloud.org/server/9.0/developer_manual/android_library/library_installation.html
- Examples: https://doc.owncloud.org/server/9.0/developer_manual/android_library/examples.html
You must be logged in to post a comment.