Skip to content

Convert files to data URLs on webhook post#2185

Open
8W9aG wants to merge 5 commits intomainfrom
sackfield/convert-files-data-urls-webhooks
Open

Convert files to data URLs on webhook post#2185
8W9aG wants to merge 5 commits intomainfrom
sackfield/convert-files-data-urls-webhooks

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.

3 participants