0

I am building an Android App where I need to send files to a Nextcloud Server.

So I looked in the API Documents (you can find it here: https://docs.nextcloud.com/server/stable/developer_manual/client_apis/android_library/examples.html)
under the section File Upload there is an Example for File Upload. But there are a few Problems.

  1. I need the absolute File path from the File which I want to upload.
  2. I need to do a PUT Request over the Nextcloud API you can find the Code below

So I created an Intent where I can pick an Image and get the Uri from it. But now I got the problem that the Nextcloud API need the the absolute Path from the File. So I tried different ways to get that path like here: Get file path of image on Android

But that didn't work for me; I got the error Message:

CursorWindow: Failed to read row 0, column -1 from a CursorWindow which has 1 rows, 6 columns

After hours of searching I found this: How to get REAL file path from android file

There someone said:

"from API 29 or Android 10 we can't get the actual path of the file"

So do I need to take an other SDK to get that right, if yes which one?

So a short look in the Nextcloud API and I can find this example Code for the File upload:

private void startUpload(File fileToUpload, String remotePath, String mimeType) {
  UploadRemoteFileOperation uploadOperation = new 
              UploadRemoteFileOperation(fileToUpload.getAbsolutePath(), remotePath, mimeType);
  uploadOperation.addDatatransferProgressListener(this);
  uploadOperation.execute(mClient, this, mHandler);
}

@Override
public void onRemoteOperationFinish(RemoteOperation operation, RemoteOperationResult result) {
  if (operation instanceof UploadRemoteFileOperation) {
    if (result.isSuccess()) {
      // do your stuff here
    }
  }
}

@Override
public void onTransferProgress(long progressRate, long totalTransferredSoFar, long totalToTransfer, String fileName) {
  mHandler.post(new Runnable() {
    @Override
    public void run() {
      // do your UI updates about progress here
    }
  });
}

So I just copied it and gave my params to it, the log result is first:

OwnCloudClient #0: Creating OwnCloudClient

and then (If I take a self created Path which I look up in the Phone):

OwnCloudClient #0: REQUEST PUT /remote.php/webdav/files/user/filename

But there is no File in my Nextcloud. So I decided to try out if I can send a PUT Request in general to the Server if it is Available. And with curl I tried to send a PUT request to the Server to upload a File from my local PC. That worked instant so I will show you what I typed in the console:

curl --user "username:password" -T "path\to\file" "http://domain.dns.net/remote.php/dav/files/username/filename"

That worked for a .txt and for a .jpg File. The Path to the Nextcloud Server until username/ is fix in the API Documentation. So you can just add folder/filename or just filename to save it on the Server.

Here is the WebDav API from Nextcloud: https://docs.nextcloud.com/server/stable/developer_manual/client_apis/WebDAV/basic.html#uploading-files

So maybe is there a way that I can do a WebDav handling in my App out of the Nextcloud API? But either there is a way to do the WebDav thing out of the API I still need the full file Path from the File which I want to upload to the Server. On the device I was in the Gallery to get the Path and it looks like that:

String tstPfad = "storage/emulated/0/Pictures/IMG_20210829_151952_1.jpg";

is this a full Path or is there something missing?

Jason Aller
  • 3,541
  • 28
  • 38
  • 38

0 Answers0