Skip to content
Back

Cannot open file, path = '/usr/local/server/protos/test.proto

  • 0
  • Cloud
Ankit Maniya
7 Mar, 2025, 23:03

I want to read file which i have added in my cloud function what is the path in cloud so I can access it

TypeScript
if (request.path == "/read_proto") {
      // Define the path to your .proto file
      String filePath = '${io.Directory.current.path}/protos/test.proto';

      try {
        // Read the file as text
        String content = io.File(filePath).readAsStringSync();

        return response.json({
          'path': request.path,
          'proto': content,
        });
      } catch (e) {
        return response.json({
          'path': request.path,
          'error': e.toString(),
        });
      }
    }

"error": "PathNotFoundException: Cannot open file, path = '/usr/local/server/protos/test.proto' (OS Error: No such file or directory, errno = 2)"

I have dart function in following structure

TypeScript
dart_func
- lib/
- protos/
TL;DR
Developers are trying to read a ".proto" file in a cloud function but facing "Cannot open file" error. The file path is incorrect as "/usr/local/server/protos/test.proto" does not exist in the cloud. Developers are recommended to use the correct path like "io.Directory.current.path/protos/test.proto". This should resolve the issue.
Ankit Maniya
7 Mar, 2025, 23:07

Cannot open file, path = '/usr/local/server/protos/test.proto

Steven
7 Mar, 2025, 23:29

You won't be able to do this with go because your code is compiled and only the compiled binary is deployed

Ankit Maniya
7 Mar, 2025, 23:35
Ankit Maniya
7 Mar, 2025, 23:36

I tried this way and got this error

TypeScript
"error": "PathNotFoundException: Cannot open file, path = '/usr/local/server/src/function/../protos/test.proto' (OS Error: No such file or directory, errno = 2)"
Ankit Maniya
7 Mar, 2025, 23:36
TypeScript
final protosFolder =
          p.join(p.dirname(io.Platform.script.toFilePath()), '../protos');
final protosFilePath = p.join(protosFolder, "test.proto");

  // Read the file as text
  String content = io.File(protosFilePath).readAsStringSync();
Steven
7 Mar, 2025, 23:37

Sorry I don't think that works

Ankit Maniya
7 Mar, 2025, 23:40

with go?

Steven
7 Mar, 2025, 23:40

Sorry same with dart. Dart is also compiled

Ankit Maniya
7 Mar, 2025, 23:41

Okay, Thank you for your time.

Ankit Maniya
7 Mar, 2025, 23:57

I have one question, if I upload file in storage is there any way I can make it publically so I don't need to authenticate for file

TypeScript
https://cloud.appwrite.io/v1/storage/buckets/67cb873900041825c482/files/67cb877300353e5b4122/view?project=67ae34c00007ef221886&mode=admin
Steven
7 Mar, 2025, 23:58

Sure. Configure the permissions for the bucket and possibly file

Ankit Maniya
7 Mar, 2025, 23:59

Yeah, I just figured it out. Thanks

For function, will it have support in future for read/add temp file when we deploy function?

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