Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix: use native apis to read file contents #1348

Open
wants to merge 6 commits into
base: main
Choose a base branch
from

Conversation

ItzNotABug
Copy link
Contributor

What does this PR do?

(Provide a description of what this PR does.)

Test Plan

(Write your test plan here. If you changed any code, please provide us with clear instructions on how you verified your changes work.)

Related PRs and Issues

(If this PR is related to any other PR or resolves any issue or related to any issue link all related PR and issues here.)

Have you read the Contributing Guidelines on issues?

(Write your answer here.)

@ItzNotABug ItzNotABug marked this pull request as ready for review September 16, 2024 07:20
@coolify-appwrite-org
Copy link

coolify-appwrite-org bot commented Sep 16, 2024

The preview deployment is ready. 🟢

Open Preview | Open Build Logs

Last updated at: 2024-09-25 17:04:25 CET

@@ -847,7 +848,8 @@ return function ($context) {
case 'json':
return $context->res->json(["type" => "This is a JSON response"]);
case 'binary':
return $context->res->binary(InputFile::withPath('file.png'));
$fileContent = file_get_contents('file.png');
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Let's check with Steven for confirmation. I think it would be better to have a snippet that can do relative path. Because with absolute you would need to /usr/local/server/src/function/[MY_PATH], which is very hard to remember

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Let's check with Steven for confirmation. I think it would be better to have a snippet that can do relative path. Because with absolute you would need to /usr/local/server/src/function/[MY_PATH], which is very hard to remember

Yep. I think that'd fall on other runtimes too, right?

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This gets very tricky due to how some runtimes will include the assets in the source vs others won't.

The code sample we currently have is essentially relative. We should just stick to that and ensure we use a consistent path for all examples.

@@ -939,7 +945,7 @@ func Main(Context openruntimes.Context) openruntimes.Response {
case "json":
return Context.Res.Json(map[string]string{"type": "This is a JSON response"})
case "binary":
file, _ := os.Open("./destiny.png")
file, _ := os.Open("./file.png")
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

In compiled languages not all files are copied, instead, only compilation output.
For this to work, you would need additional command during build step to copy your asset files.
Possible, but to keep it simple we could do: https://gobyexample.com/embed-directive

Let's check other compiled languages and see if they have something similar: C++, Dart, Dotnet, Java/Kotlin, Swift

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants