Quantcast
Channel: Xamarin.Forms — Xamarin Community Forums
Viewing all articles
Browse latest Browse all 91519

Working with files

$
0
0

Hi, I'm trying to create an uploader app.
I created this app in UWP before, now I want to create this in xamarin.forms.

I used file picker (from Xam.Plugin.FilePicker nuget) as my file picker.
after picking file from removable storage(external storage - sd card) bytes array length is 0 but picker can get file name.

permissions:

    <uses-permission android:name="android.permission.INTERNET" />

    <uses-permission android:name="android.permission.WRITE_EXTERNAL_STORAGE" />

    <uses-permission android:name="android.permission.READ_EXTERNAL_STORAGE" />

    <uses-permission android:name="android.permission.ACCESS_NETWORK_STATE" />

here is my code

                // Check and grant storage access from user
                await BaseR.CheckAndGrantAccess();

                // check network available
                if (!BaseR.GetInternetConnectivity())
                {
                    await DisplayAlert("No network", "No internet connection found.\r\n" +
                        "Please connect to internet and try again", "OK");

                    return;
                }
                FileData filedata = new FileData();
                filedata = await CrossFilePicker.Current.PickFile();
                if (filedata == null)
                    return;

                Debug.WriteLine("fileData " + (filedata.DataArray == null ? " Is " : " Not ") + " null");
                Debug.WriteLine("Bytes: " + filedata.DataArray?.Length);
                Debug.WriteLine("FileName: " + filedata.FileName);

Debug output:

[0:] fileData  Not  null
[0:] Bytes: 0
[0:] FileName: CTR.PNG

as you see bytes array is 0, I tested this app in real phone with Android 7.0.

What is the problem?
Is there anything I have to do?

Thanks

Ramtin


Viewing all articles
Browse latest Browse all 91519

Trending Articles



<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>