Back

FileSystemException: Cannot open file, path = 'file:///usr/local/server/src/static/index.html' (OS E

  • 1
  • Self Hosted
  • Functions
Shiba
6 Nov, 2023, 03:40

Just copied the util.dart file

TL;DR
The user is getting a "FileSystemException: Cannot open file" error when trying to open a file path. Another user suggests using a string in the code instead of a static file. The user also mentions a pull request pending on this issue. After some discussion and sharing code snippets, it is suggested to check the file structure and ensure that the html file is in a folder named 'static'. The solution is to change the code to read the file from the static folder using the correct path.
Shiba
6 Nov, 2023, 03:40

To my code

Shiba
6 Nov, 2023, 03:40

And pushed using the CLI

Drake
6 Nov, 2023, 03:41

What's your folder structure and what's the function in your appwrite.json?

Shiba
6 Nov, 2023, 03:44
Shiba
6 Nov, 2023, 03:44
TypeScript
    "projectId": "64fff1b78429690cbb74",
    "projectName": "windope",
    "functions": [
        {
            "$id": "65480141667102a7bf37",
            "name": "site",
            "runtime": "dart-2.17",
            "execute": [],
            "events": [],
            "schedule": "",
            "timeout": 15,
            "enabled": true,
            "logging": true,
            "entrypoint": "lib/main.dart",
            "commands": "dart pub get",
            "ignore": [
                ".packages",
                ".dart_tool"
            ],
            "path": "./"
        }
    ]
}
Shiba
6 Nov, 2023, 03:45
TypeScript

final String _dirname = Platform.script.toFilePath();
final String staticFolder = '${Uri.file(_dirname).resolve('../static')}';

/// Throws an error if any of the keys are missing from the object
/// @param obj - The object to check
/// @param keys - The list of keys to check for
/// @throws Exception
void throwIfMissing(Map<String, dynamic> obj, List<String> keys) {
  final missing = <String>[];
  for (var key in keys) {
    if (!obj.containsKey(key) || obj[key] == null) {
      missing.add(key);
    }
  }
  if (missing.isNotEmpty) {
    throw Exception('Missing required fields: ${missing.join(', ')}');
  }
}

/// Returns the contents of a file in the static folder
/// @param fileName - The name of the file to read
/// @returns Contents of static/{fileName}
Future<String> getStaticFile(String fileName) {
  return File('index.html').readAsString();
}
Shiba
6 Nov, 2023, 03:46

even I have done this dart return File('index.html').readAsString();

Drake
6 Nov, 2023, 03:46

Look at the files in the template. The html file should be in a folder named static

Shiba
6 Nov, 2023, 03:46

yes I have done that only in the begning

Shiba
6 Nov, 2023, 03:46

still same error

Drake
6 Nov, 2023, 03:47

What?

Shiba
6 Nov, 2023, 03:48
TypeScript
  return File('index.html').readAsString();
}
``` have hardcored the file path
Drake
6 Nov, 2023, 03:49

Have you tried doing it as the template does?

Shiba
6 Nov, 2023, 03:49

In the starting I have followed the same file structure

Shiba
6 Nov, 2023, 03:50

Yes I have

Shiba
6 Nov, 2023, 03:50

getting the same error

Drake
6 Nov, 2023, 03:50

Please share what you have after you change it to what the template did

Shiba
6 Nov, 2023, 04:02

its simply serves a index.html on GET at /

Drake
6 Nov, 2023, 23:07

hmm odd...let me check with the team

Shiba
7 Nov, 2023, 16:26

yes I am contributing to appwrite/template ,

Shiba
9 Nov, 2023, 08:19

pull request just pending on this @Drake

Drake
24 Nov, 2023, 14:34

For now, you might want to put a string in your code rather than trying to have a static file

Arvind Sangwan
19 Dec, 2023, 08:47

I'm experiencing the same problem. any solution?

Error:- PathNotFoundException: Cannot open file, path = 'file:///usr/local/server/src/static/index.html' (OS Error: No such file or directory, errno = 2)

Reply

Reply to this thread by joining our Discord

Reply on Discord

Need support?

Join our Discord

Get community support by joining our Discord server.

Join Discord

Get premium support

Join Appwrite Pro and get email support from our team.

Learn more