Skip to content

DocumentFile.createFile returns null instead of creating a file #8028

@zell-mbc

Description

@zell-mbc

I am the developer of an application and I'd like to offer my users the possibility to create backups/exports on Nextcloud.
I seem to have a similar issue as this #7350 which unfortunately didn't get resolved.

I can select the Nextcloud folder just fine and get what I think is a proper Uri back.
But when I execute createFile I run into a Failed to create document exception. File type and selected folder don’t seem to matter.

According to the issue referenced above, this should work, but I can’t figure out where things go wrong for me.

The below screen shot shows my code sequence with the content of the variables for reference:

image

Steps to reproduce

  1. Select folder from Nextcloud storage provider
    image

image

  1. Execute DocumentFile.FromTreeUri
  2. Try to create a file in selected folder via folder.createFile

Expected behaviour

  • createFile returns a Uri for an empty file

Actual behaviour

  • createFile returns null, always

Environment data

Android version: 11

Device model: OnePlus 8 Pro

Stock or customized system: Stock

Nextcloud app version: 3.15.0

Nextcloud server version: 20.0.7

Stack trace:

W/DocumentsContract: Failed to create document
    android.os.ParcelableException: java.io.FileNotFoundException: Failed to upload document with path /MediLog-2021-02-22.csv
        at android.os.ParcelableException$1.createFromParcel(ParcelableException.java:82)
        at android.os.ParcelableException$1.createFromParcel(ParcelableException.java:79)
        at android.os.Parcel.readParcelable(Parcel.java:3281)
        at android.os.Parcel.createExceptionOrNull(Parcel.java:2368)
        at android.os.Parcel.createException(Parcel.java:2357)
        at android.os.Parcel.readException(Parcel.java:2340)
        at android.database.DatabaseUtils.readExceptionFromParcel(DatabaseUtils.java:190)
        at android.database.DatabaseUtils.readExceptionFromParcel(DatabaseUtils.java:142)
        at android.content.ContentProviderProxy.call(ContentProviderNative.java:755)
        at android.content.ContentResolver.call(ContentResolver.java:2449)
        at android.provider.DocumentsContract.createDocument(DocumentsContract.java:1375)
        at androidx.documentfile.provider.TreeDocumentFile.createFile(TreeDocumentFile.java:53)
        at androidx.documentfile.provider.TreeDocumentFile.createFile(TreeDocumentFile.java:45)
        at com.zell_mbc.medilog.data.ViewModel.exportCSVFile(ViewModel.kt:372)
        at com.zell_mbc.medilog.MainActivity.onActivityResult(MainActivity.kt:680)
        at android.app.Activity.dispatchActivityResult(Activity.java:8316)
        at android.app.ActivityThread.deliverResults(ActivityThread.java:5164)
        at android.app.ActivityThread.handleSendResult(ActivityThread.java:5212)
        at android.app.servertransaction.ActivityResultItem.execute(ActivityResultItem.java:51)
        at android.app.servertransaction.TransactionExecutor.executeCallbacks(TransactionExecutor.java:135)
        at android.app.servertransaction.TransactionExecutor.execute(TransactionExecutor.java:95)
        at android.app.ActivityThread$H.handleMessage(ActivityThread.java:2198)
        at android.os.Handler.dispatchMessage(Handler.java:106)
        at android.os.Looper.loop(Looper.java:233)
        at android.app.ActivityThread.main(ActivityThread.java:7959)
        at java.lang.reflect.Method.invoke(Native Method)
        at com.android.internal.os.RuntimeInit$MethodAndArgsCaller.run(RuntimeInit.java:631)
        at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:978)
     Caused by: java.io.FileNotFoundException: Failed to upload document with path /MediLog-2021-02-22.csv
        at java.lang.reflect.Constructor.newInstance0(Native Method)
        at java.lang.reflect.Constructor.newInstance(Constructor.java:343)
        at android.os.ParcelableException.readFromParcel(ParcelableException.java:56)

Metadata

Metadata

Assignees

No one assigned

    Labels

    bugneeds infoWaiting for info from user(s). Issues with this label will auto-stale.

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions