Dynamically set ImageUploadEditor filename #7106
Replies: 7 comments 1 reply
-
Please any help will be greatly appreciated @VictorTomaili |
Beta Was this translation helpful? Give feedback.
-
Thank you @LSNicholls , |
Beta Was this translation helpful? Give feedback.
-
I see. Well, using values from the row will not work, unless the dropdown value is persisted to the database first. So... Here are some questions for you -- assuming you really do want to store this value, which I'm not sure you need to do at all:
However... I don't really understand why you are using an UploadEditor control here. You already have the files, you know what they are, and the user isn't going to upload anything. Why wouldn't you use an img? If you still want to store the source URL for the img in the database row, questions 1 and 2 above would still apply, but I would get rid of your upload control and embed the image instead. You just need a div or something that you dynamically adjust. (Use StaticTextBlock for this, in other words.) With this approach, it seems to me that you could do what you originally wanted to do (load the thing in script in the TS) instead of generating the value as a column in the row, if you want. The timing wouldn't matter as much, so questions 1 and 2 wouldn't apply. |
Beta Was this translation helpful? Give feedback.
-
Hi @LSNicholls, |
Beta Was this translation helpful? Give feedback.
-
Well, then I think using the ImageUploadEditor with FilenameFormat template should work for you. (Read the links that I included in my first response, and tell me if you don't understand how this will work.) You just need to use this.isNew() in the dialog's afterLoadEntity(), I think, to determine when you need to disable or hide/remove the upload editor control because the relation hasn't been selected yet. Refer to my questions 1 and 2, in the second comment. |
Beta Was this translation helpful? Give feedback.
-
Ok, will try that, but how do i use the FilenameFormat in the .ts file to load the image when the Relation is selected because it seems the FilenameFormat property is only at the server side .cs |
Beta Was this translation helpful? Give feedback.
-
You don't use it in the .ts file. You don't have to do anything in the .ts file. It's in the CS but it is dynamic, because you reference a column in the row (use the pipe delimiters), and the value in this column is determined by the relative that they chose. It's a little hard to explain without knowing your data structures, but it is absolutely possible. Also, I'm not clear on whether Abigail is another application user, but that is what it sounds like, from your first explanation. So, presumably, if Abigail has uploaded a user image already for herself (I have a "My Profile" dialog for stuff like this, not clear how you do it), you can join from your RelativeId to the UserId in the Users table, and pick up this filename value. If this filename already exists, because Abigail or an administrator has attached a photo to her User row, did you want the relative to see it? Or do you want every relative to always upload their own photo of their relative to this row? If the latter, then I think you need a way to distinguish between different photos of the same relative, for each member who might be related to the same person. IOW: Let's say your folder (under ~/App_Data/upload/, or whatever your upload path is) is called RelativeImages. You will need either a subfolder for each user here, so each one who is related to Abigail has their own photo of her, or you need to use a prefix for each person, rather than just Abigail's name, to ensure they stay unique. For example, if your current User's UserId is 53, that User's photo for Abigail could be RelativeImages/53/AbigailAgyapong.png, or it could be RelativeImages/53-AbigailAgyapong.png. Does this make sense so far? If using the separate folders, your FilenameFormat attribute might look like this:
OTOH, if you are using the same photo for all people related to Abigail, and you have that value in PhotoUrl, that's fine too. Is PhotoUrl pathed? If so, you'll just want the filename without the path (parse it out if necessary) . Your FilenameFormat attribute might look like this:
I am sorry if I am confusing you. There are a couple of things about your description and the workflow that is supposed to take place that I am having trouble understanding. I hope my questions in this comment help you see why. Also, you notice that I say "IncludingFileExtension". If you are expecting people to upload images BUT you are also pre-selecting what the filename should be, before they upload, I think you are going to have to either limit the allowed Extensions to exactly 1 type (using the ImageExtensions attribute) or you are going to have to post-fix the filename value after they upload, to use the extension that they ended up uploading (you will have it, if you use a separate column to store OriginalName, this is another attribute on the editor). |
Beta Was this translation helpful? Give feedback.
-
Please how can I set ImageUploadEditor filename dynamically in dialog.ts, what I have done is not working
Beta Was this translation helpful? Give feedback.
All reactions