What data is send to the server when a file is uploaded?

I'm optimizing a mobile app during bad cellular connections related to uploading photo's. In doing so, I would like to exactly know what data is send to the server, once the Mendix applications wants to upload data.   Context: I've built a Javascript function that fires once a file is selected through the FileUploader. That function resizes and compresses the image, often from 2-5MB down to 50-100KB. The image is converted to Base64, since you can't replace the actual file in a FileUploader. This Base64 string is set on a seperate attribute of the FileDocument entity. Through a seperate microflow, this Base64 string is encoded to a file and attached onto the FileDocument, instead of the original File that was uploaded. When a file is uploaded and a microflow runs, the uploaded file by Mendix default is uploaded to the server. My thought of replacing the document through the microflow with the encoded Base64 as of that doesn't work, since the original 5MB file is still transferred to the server. Even though the compressed one will eventually be saved, the time to transfer 5MB over a (often very) bad cellular connection still takes a long time. I simply want to replace the File that is transferred to the server, with the compressed one. In order to, hopefully do that correctly, I need to know what is transferred to the server. More specificially: Is the file that is attached to the FileUploader uploaded to the server or the file inside the FileDocument object? I cannot replace the FileUploader file, but I can, hopefully, replace the file inside the object via the Mx API (obj.set(‘file’, ‘compressedFile’)). Thanks for helping out in this rather complex matter.
1 answers

You can try to clear the field ‘blob’ from the formData. Use the browser to inspect the message that is sent. In my case it looks like (upload)


Content-Disposition: form-data; name="data"

Content-Disposition: form-data; name="blob"; filename="switch-off-icon.png"
Content-Type: image/png

Followed by encoded data.

As alternative you can use a seperate (optionally non persistent) entity to pass the string the server and do the uncompressing there.

On the server the filedocument is in a separate file on disk, but when a filedocument is passed thru the api it contains binary data.

I would recommend to create a custom widget.