marten
marten copied to clipboard
feat: add JSON representation for Marten::HTTP::UploadedFile
This change introduces a to_json method to Marten::HTTP::UploadedFile, allowing uploaded files to be included in JSON representations such as request.data.to_json.
Previously, converting a request containing an uploaded file to JSON raised:
Error: expected argument #1 to 'Marten::HTTP::UploadedFile#to_json' to be IO, not JSON::Builder
The new implementation defines #to_json and #to_json(json : JSON::Builder), returning an object with the following fields:
original_filenametempfilecontent_type
This makes it possible to safely serialize uploaded files in request data.
I was inspired by ruby rack implementation (src):
puts Rack::Multipart::UploadedFile.new("/usr/bin/nvim").to_json
{"original_filename":"nvim","tempfile":"#<File:0x00007f2e4d386648>","content_type":"text/plain"}