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

Convert files to data URLs on webhook post #2185

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

Conversation

8W9aG
Copy link
Contributor

@8W9aG 8W9aG commented Mar 6, 2025

  • When posting a webhook we can end up with files referencing /tmp folders that can’t be accessed by the consumer of the webhook
  • Convert these files to data URLs so they can be consumed.

8W9aG added 3 commits March 6, 2025 09:22
* When posting a webhook we can end up with files
referencing /tmp folders that can’t be accessed by
the consumer of the webhook
* Convert these files to data URLs so they can be
consumed.
* upload_files needs to know if the payload has a
Path object
Comment on lines 56 to 60
if "output" in response_object:
response_object["output"] = upload_files(
response_object["output"],
upload_file=upload_file, # type: ignore
)
Copy link
Contributor

Choose a reason for hiding this comment

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

What was the thinking of doing this here in the webhook handler rather than in the worker where we currently do the file uploads?

if self._file_uploader is None:
return output

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Doing it there breaks a lot of tests, assumed that this was required behaviour based on those tests, and given that the problem is targeted on webhooks it made sense to move it to there. Let me know if you think any of that is mistaken.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Had a chat with @aron and we will move this to the runner and see in the CI what breaks in terms of tests, updated in: 8707aba

"input": {},
}
response = PredictionResponse(**payload)
payload["output"] = "data:None;base64,aGVsbG8gd29ybGQ="
Copy link
Contributor

Choose a reason for hiding this comment

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

Is None supposed to be here?

Suggested change
payload["output"] = "data:None;base64,aGVsbG8gd29ybGQ="
payload["output"] = "data:text/plain;base64,aGVsbG8gd29ybGQ="

Copy link
Contributor

@aron aron Mar 6, 2025

Choose a reason for hiding this comment

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

Actually, what is this test doing?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

It tests that the webhook is sent data URLs rather than tmp file directories. I can change the mime-type however it seems odd to me that the upload_file function uses None as a default if that default is considered itself invalid. Can you comment on that?

"output": Path(tmpfile.name),
"input": {},
}
response = PredictionResponse(**payload)
Copy link
Contributor

Choose a reason for hiding this comment

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

Ok just for my understanding, without the change we would've passed back the path to the /tmp file which then the caller could not access, so we're uploading the file (somewhere) and passing a URL back? And then the line below has a b64 encoded URL

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.

None yet

3 participants