ktor 3.0.0 server static files in android seems no...
# ktor
c
ktor 3.0.0 server static files in android seems not working.
a
What request do you make to access the
a.txt
file?
It should be
<http://host>:port/d/a.txt
c
I was expected a file list like nginx/apache. A specific file access is confirmed to be working. Thanks. 🙂
Can ktor static files list files?
preferably recursive.
it seems only files created by myself can be listed.
there are more than six files in the download directory, I only can list my created by my program, which is the only one file called
a.txt
, while other files not created by my program can't be accessed.
a
Please take a look at this sample project, which shows how to implement web file listing.
c
Thanks. how to solve the problem that other files can't be accessed?
a
Can you give an example of such a file?
c
i created a.txt file inside download directory, it can be listed. but other files saved by other programs can't be accessed. you can test this program in your android device to see if it is true.
a
The problem is that the file
a.txt
isn't actually created in the
Download
directory. Can you share the steps to reproduce the problem using your application?
c
Images shows the result when i manually created the a.txt in the download directory.
a.txt is the only file found in the directory while there are more files available.
a
I mean the
a.txt
file isn't created by your application when the
Download
directory is empty.
Can you share step by step how to reproduce the problem using your application?
c
yes. but it doesn't change the result. You can change
if (file.exists()) {
to
if (!file.exists()) {
to create the file in
ip.kt
line
46
.
a
What do you mean?
If the file isn't in the directory Ktor server cannot serve it
c
a.txt is not auto created by previous version. add the missing
!
can auto creating the
a.txt
file and can see the file be read from the download directory. and other files can't be read.
a
Can you describe how to create "other" files?
c
I don't need to create other files, I need to be able to read other files.
a
How can I reproduce the problem?
c
what do you get when tap the ipv4 address without
/d.
if you get only
Hello from Ktor! a.txt
then you download directory files are not accessible to the program if the download directory contains more file than just
a.txt
my ipv4 is 192.168.0.104, so I clicked the
<http://192.168.0.104:10086>
button.
a
As I can see, in the handler of the
/
route, you collect files contained in the
Download
directory via the Android API. Then the files are serialized to a string and responded to the client. Can you tell me how is your problem related to Ktor?
c
I can't read all files in
Download
directory.
a
I understand that. Can you do it without Ktor?
c
can you read all files in the
Download
directory?
But I want to take advantage of Ktor to reduce my development time.
a
I don't say that you shouldn't use Ktor. I am asking you to check if the problem occurs without using Ktor to determine whether it's related to Ktor or not.
c
Seems a problem of Android.
Copy code
val directory: File = File(Environment.getExternalStoragePublicDirectory(Environment.DIRECTORY_DOWNLOADS).toString())
                        val files = directory.listFiles()
I read files use standard apis. And it can't return other files.