File upload questions

Good day,
Have a few questions I would like to ask in regards to file upload.

I’m investigating the question of uploading a file using rest api.
I did find information in regards to how it should look like: a text field on one side, and a

{
    "variables": {
        "field1":{
            "value": {
                "type": "File",
                "valueInfo": {
                        "filename": "pic.png",
                        "mimeType": "image/png"
                },
                "field1": "iVBORw0KGgoAAAANSUhEUgAABTAAAAJQCAYAAAC5Pku2AAAAAXNSR0IArs4c6QAAIABJREFUeF7s3Qm8TeX7//8rocxEkjmSimRsIqIoKT5IRSIlQ6XJECmlNItSCJUMiTIUUSKJSoWiKInMKmTI0Mz/8V7f39n/"
            }
        }
    }
}

on the other.

But is it properly handled? And how exactly is it handled in terms of persistence - is it wrapped as a tmp file, or does it go into the DB as a variable? And how to manipulate/configure this behavior?

I did find act_hi_detail table, which, if I’m not mistaking, is related to variable history.

From there I had two tests done - one to upload a dummy file using javaDelegate:

execution.setVariable("myFile", new File(...));

And the other one was using rest API.

And here is what I got:

name_	var_type_	text2_
field1	spin://application/json	java.util.LinkedHashMap<java.lang.Object,java.lang.Object>

and this is for the file upload using delegate:

spin://application/json	java.io.File

Making my second question - is the rest api file upload done correctly?

BTW: Camunda 7

Thank you in advance


Small update: I have traced the rest api to act_ge_bytearray, and found that it is stored in DB.
I’m either doing something wrong, or assuming something wrong.

I realized that act_ge_bytearray has both files stored as bytearray in the DB. Am I missing something?

@Niall @GotnOGuts (sorry, Guts, but maybe you know how to deal with this :smiley: )

I don’t know the internals of the engine well enough to really comment.
But yes, act_ge_bytearray is the table where files would be stored from my understanding, and they’ll be stored as byte arrays.

With the REST interface giving you a LinkedHashMap type rather than a file, I think you’ve got something wrong, but unfortuately, I can’t explain what you got wrong.

Reading Complete Task | docs.camunda.org
makes me think that the REST JSON block should be

{
    "variables": {
        "field1": {
            "value": "iVBORw0KGgoAAAANSUhEUgAABTAAAAJQCAYAAAC5Pku2AAAAAXNSR0IArs4c6QAAIABJREFUeF7s3Qm8TeX7//8rocxEkjmSimRsIqIoKT5IRSIlQ6XJECmlNItSCJUMiTIUUSKJSoWiKInMKmTI0Mz/8V7f39n/",
            "type": "File",
            "valueInfo": {
                "filename": "pic.png",
                "mimeType": "image/png"
            }
        }
    }
}

@GotnOGuts thanks. I was hoping that maybe you would shed some light on the situation.

I don’t think it is a problem with how the data is posted, but a problem with how Spring Boot Camunda is handling it (or not).

I also thought in the beginning that maybe I’m posting it somehow wrong, and for that made a test connector with one simple task

execution.setVariable("myFile", new File(...));

And squished a 20mb file there (the documentation did state that there should be a threshold for this kind of stuff).

DB reflected this variable with, at least, io.File, but still had a link to ge_bytearray with its internals stored in the table itself.

Guess I’ll need to think of “Plan B” (darn, I really hate Plan B).

io.File seems like it should be the correct type.
The LinkedHashMap seems to be the one that’s incorrect… which was driving my thought that it was the JSON that wasn’t happy.

The format of your JSON doesn’t 100% match the docs that I linked to, and I can see how the REST API could get confused, thinking that the JSON block in the Value was the text to set the variable to.

"value": {
                "type": "File",
                "valueInfo": {
                        "filename": "pic.png",
                        "mimeType": "image/png"
                },
                "field1": "iVBORw0KGgoAAAANSUhEUgAABTAAAAJQCAYAAAC5Pku2AAAAAXNSR0IArs4c6QAAIABJREFUeF7s3Qm8TeX7//8rocxEkjmSimRsIqIoKT5IRSIlQ6XJECmlNItSCJUMiTIUUSKJSoWiKInMKmTI0Mz/8V7f39n/"
            }

as compared to

"value": "iVBORw0KGgoAAAANSUhEUgAABTAAAAJQCAYAAAC5Pku2AAAAAXNSR0IArs4c6QAAIABJREFUeF7s3Qm8TeX7//8rocxEkjmSimRsIqIoKT5IRSIlQ6XJECmlNItSCJUMiTIUUSKJSoWiKInMKmTI0Mz/8V7f39n/",

Even with io.File, the variable gets the record in bytearray table (and I can see the value stored as well).

Yes.
act_ge_bytearray is where any “complex” (think along the lines of ‘not a primitive’) variable is stored.

And that’s the problem. Originally, I had an assumption that Camunda handles file upload, dumping data into physical storage, and not into DB.

Guess it’s time for Plan B with interceptors and stuff.