[Multiple File Upload] How do I add other attribute into the UploadCache entity

Forge Component
(43)
Published on 2 Jan by Remco Dekkinga
43 votes
Published on 2 Jan by Remco Dekkinga

Since I want to add a relationship between the files that I upload and another entity so when i call a record or the entity i can get the files that only have the correct identifier of the entity from UploadCache.

However, I do not see the way that I can, let's say, get the id of the newly uploaded files (Let's assume multiple uploads) so i can do some linkage by assigning values.

Is there a way to accomplish this?

I use SessionId for this and make sure its unique.

On after Upload you can call a new action that checks the files in the UploadCache. This action should add the files to a final location (fileserver or database) and after saving, you get the identifier / location that you can use in the other entity.

The UploadCache is automatically cleaned after x minutes, but a best practice is to remove the file from the cache after a successful save action.

Kind regards,

Remco Dekkinga

Raymond Lips wrote:

I use SessionId for this and make sure its unique.

Thank you Raymond for your response. Can you elaborate a bit more on how you did it? I checked the sample it used a text for the session id in parameter. What do you use instead?

I create an 'unique' string as sessionId. When I need to add files to existing records of an entity, I often use a combination of an entity name and identifier.  In the action that I call after the upload I use that string to get the data from the UploadCache entity and copy the data to the final location. 

After that, I delete the record in UploadCache.


Raymond Lips wrote:

I create an 'unique' string as sessionId. When I need to add files to existing records of an entity, I often use a combination of an entity name and identifier.  In the action that I call after the upload I use that string to get the data from the UploadCache entity and copy the data to the final location. 

After that, I delete the record in UploadCache.


Thanks for the response! But I cannot amend the action of uploading. It is getting the MultipleFileUpload web block from the producer module. 


Let's say I upload 2 files at the same time. From the demo, the MultipleFileUpload only calls the refresh function. How to I get the info of the 2 files (Content, file name, etc.) that I just uploaded a second before? If I upload 2 files and after 5 mins I upload another 2 files, wouldn't such session ID (entity name and identifier) get the previously 2 files and re-insert into the entity again? (So in total of 4 files, it now inserted 6 files into the entity.)

Solution

In the On notify of the MFU webblock I use something like this. So when I have processed the file, I delete the file from the UploadCache entity to make sure it only gets processed once.

Solution

Hello Raymond,

I have a similar requirement of multiple file upload. If your demo (MFUdemo) is working, could you share it here pls.

Regards,

Smitha

Raymond Lips wrote:

In the On notify of the MFU webblock I use something like this. So when I have processed the file, I delete the file from the UploadCache entity to make sure it only gets processed once.

Sorry for the late response and thank you very much for your answer Raymond. I did the same and set the SessionId to be getUserId() [assuming the same user account cannot be logged in elsewhere] and do the same as you described in the picture. It works like a magic thank you very much.