Upload a picture via the form, What do I do wrong

Following the instructions step by step as elaborated in this post:

https://www.outsystems.com/forums/discussion/36927/how-to-upload-an-image-with-outsystems-beginner/

(only difference: I am not working with a separate entity for storing the photo (tried that as well, but with same result).

So, I dropped the upload widget, dropped a button, named it "Upload photo", created the action (dclicked the button), created a local variable to hold the data (with the entity as datatype), dropped an assign in the flow, set the conditions (localvariabe.Id = inputvariable & localvariable.photo = uploadwidget). 

My action looks exactly like in the explanation, however, uploading seems to fail. I experimented a lot (resulting in db-issues, already resolved via this forum) but still I got stuck on this uploading part. 

When uploading a photo, new records are created with a blanc description, or current descriptions of the entity records I wanted to edit, disappear. 

I tried a lot of things, including setting the createorupdate action under the save-screenaction, creating a separate entity for storing the photo (not as preferred as I want to store the photo in the same entity, but failed anyway). But what am I doing wrong?


(I haven't followed the steps behind "How to show image from the database " yet, as I got stuck in this part. I checked the data via the data-tab (select entity, right mouseclick, view data")


2 questions:

- What setting is wrong?

- Is there a database administrator enviroment, that enables me to directly insert/correct the data (as the current content of the entity is blanc as a result of my experiments to upload the photo, and I can't reach the data via the detailscreen anymore......


Best...Coen


Hi Coen,

Did you make sure the Method of your upload button is set to ‘Submit’? If it’s set to ‘Ajax Submit’, the upload widget won’t work.

Regards,

Nordin

I don't have to choose any submit, and the current submit is not Ajax. I uploaded the OML

Sorry, I’m not near a computer right now. I’ll have a look tonight.

Regards,

Nordin

PS: with regard to your preference of storing the image in the same entity, it’s a performance best practice to isolate large text or binary data in a separate entity. 

Coen Hendrikx wrote:

Following the instructions step by step as elaborated in this post:

https://www.outsystems.com/forums/discussion/36927/how-to-upload-an-image-with-outsystems-beginner/

(only difference: I am not working with a separate entity for storing the photo (tried that as well, but with same result).

So, I dropped the upload widget, dropped a button, named it "Upload photo", created the action (dclicked the button), created a local variable to hold the data (with the entity as datatype), dropped an assign in the flow, set the conditions (localvariabe.Id = inputvariable & localvariable.photo = uploadwidget). 

My action looks exactly like in the explanation, however, uploading seems to fail. I experimented a lot (resulting in db-issues, already resolved via this forum) but still I got stuck on this uploading part. 

When uploading a photo, new records are created with a blanc description, or current descriptions of the entity records I wanted to edit, disappear. 

I tried a lot of things, including setting the createorupdate action under the save-screenaction, creating a separate entity for storing the photo (not as preferred as I want to store the photo in the same entity, but failed anyway). But what am I doing wrong?


(I haven't followed the steps behind "How to show image from the database " yet, as I got stuck in this part. I checked the data via the data-tab (select entity, right mouseclick, view data")


2 questions:

- What setting is wrong?

- Is there a database administrator enviroment, that enables me to directly insert/correct the data (as the current content of the entity is blanc as a result of my experiments to upload the photo, and I can't reach the data via the detailscreen anymore......


Best...Coen


Hi Coen, 


Your Database, or at least the entities Asset and Asset Type aren't equal as the post you mentioned. 

The post shows two entities where a person has a single photo (one to one relationship), which id of PersonPhoto is personId. The OML that you shared isn't quite equal right?

You have an Asset receiving an Asset Type (one to many relationship).


If you want to make this kind of relationship you should add the Asset id inside the AssetType and not the opposite. Plus, what Nordin mentioned related with the isolation of a binary is it true, you should do that, regarding outsystems best performances. 


I did debugg and tried to upload a photo and it worked but you are always overwriting the binary that is already saved for the Asset Type Id created.


Make sense?


Try to make the changes that i mentioned above.


If this problem continues to persist, let us know.


Regards



One more thing, you should have your entities with the expose read only - Yes because of security. 

And doing that you need to create the CRUD (Create, Retrieve, Update and Delete) Server Actions, in an isolate module (OML) and then consume in your app.

Pedro Santos wrote:

Coen Hendrikx wrote:

Following the instructions step by step as elaborated in this post:

https://www.outsystems.com/forums/discussion/36927/how-to-upload-an-image-with-outsystems-beginner/

(only difference: I am not working with a separate entity for storing the photo (tried that as well, but with same result).

So, I dropped the upload widget, dropped a button, named it "Upload photo", created the action (dclicked the button), created a local variable to hold the data (with the entity as datatype), dropped an assign in the flow, set the conditions (localvariabe.Id = inputvariable & localvariable.photo = uploadwidget). 

My action looks exactly like in the explanation, however, uploading seems to fail. I experimented a lot (resulting in db-issues, already resolved via this forum) but still I got stuck on this uploading part. 

When uploading a photo, new records are created with a blanc description, or current descriptions of the entity records I wanted to edit, disappear. 

I tried a lot of things, including setting the createorupdate action under the save-screenaction, creating a separate entity for storing the photo (not as preferred as I want to store the photo in the same entity, but failed anyway). But what am I doing wrong?


(I haven't followed the steps behind "How to show image from the database " yet, as I got stuck in this part. I checked the data via the data-tab (select entity, right mouseclick, view data")


2 questions:

- What setting is wrong?

- Is there a database administrator enviroment, that enables me to directly insert/correct the data (as the current content of the entity is blanc as a result of my experiments to upload the photo, and I can't reach the data via the detailscreen anymore......


Best...Coen


Hi Coen, 


Your Database, or at least the entities Asset and Asset Type aren't equal as the post you mentioned. 

The post shows two entities where a person has a single photo (one to one relationship), which id of PersonPhoto is personId. The OML that you shared isn't quite equal right?

You have an Asset receiving an Asset Type (one to many relationship).


If you want to make this kind of relationship you should add the Asset id inside the AssetType and not the opposite. Plus, what Nordin mentioned related with the isolation of a binary is it true, you should do that, regarding outsystems best performances. 


I did debugg and tried to upload a photo and it worked but you are always overwriting the binary that is already saved for the Asset Type Id created.


Make sense?


Try to make the changes that i mentioned above.


If this problem continues to persist, let us know.


Regards



Hi, there is indeed a one to many relationship from assettype to asset. But that is just to categorize the asset. The picture must be related to the assettype, not the asset. I did not create a one-to-one relationship for asset type to an entity "assettypephoto", but tried to realize it with one entity (assettype), with one of the attributes being the photo. I have also tried to do it with a one-to-one relationship, but that attempt failed as well. But, as Nordin adviced, I should always create a database with the photo's seperately in antity, so I'll give it another try and let you know. Tnx for now!


Solution

Coen Hendrikx wrote:

Following the instructions step by step as elaborated in this post:

https://www.outsystems.com/forums/discussion/36927/how-to-upload-an-image-with-outsystems-beginner/

(only difference: I am not working with a separate entity for storing the photo (tried that as well, but with same result).

So, I dropped the upload widget, dropped a button, named it "Upload photo", created the action (dclicked the button), created a local variable to hold the data (with the entity as datatype), dropped an assign in the flow, set the conditions (localvariabe.Id = inputvariable & localvariable.photo = uploadwidget). 

My action looks exactly like in the explanation, however, uploading seems to fail. I experimented a lot (resulting in db-issues, already resolved via this forum) but still I got stuck on this uploading part. 

When uploading a photo, new records are created with a blanc description, or current descriptions of the entity records I wanted to edit, disappear. 

I tried a lot of things, including setting the createorupdate action under the save-screenaction, creating a separate entity for storing the photo (not as preferred as I want to store the photo in the same entity, but failed anyway). But what am I doing wrong?


(I haven't followed the steps behind "How to show image from the database " yet, as I got stuck in this part. I checked the data via the data-tab (select entity, right mouseclick, view data")


2 questions:

- What setting is wrong?

- Is there a database administrator enviroment, that enables me to directly insert/correct the data (as the current content of the entity is blanc as a result of my experiments to upload the photo, and I can't reach the data via the detailscreen anymore......


Best...Coen


Hi Coen ,

I have done some changes on your OML and now its working fine. it will show the uploaded image and if you want to edit that images then you can do that ,also its getting stored in database...can you check once?


Please let me know if your issue is not resolved.


Hope this will resolve your problem.


Good luck!

thanks.

Solution

@Nordin: tnx for the tip, I am just prototyping now but in my final solutions, I will enclose the photo's in a separate entity.

@Pedro: 

- concerning read only: I am prototyping, But indeed, in a final solution I will take care of the security

- It is a different situation indeed, But I wanted to upload it in the same entity for now, and was experiencing issues. 

@Yogesh: after uploading your file, it worked. I rebuilded it, but got in problems again. Those were caused by the createorupdate action: Instead of selecting, I finally figured out that a "plus sign" appears in front of the source, enabling you to specify every attribute one-by-one.

One small issue left, though, I got an Ignored Ajax Refresh warning (same as yours). How can I fix this warning?

(message: The method should be set to Ajax so that AJAX refresh elements of the 'save' screen action aren't ignored)

- The pictures are stored in the database, despite of this warning

- setting the method to AJAX refresh results in another warning, advising me to switch back to the "normal" submit (seems to be a loop).


All, many thanks for the help sofar!


Hi Coen,

You’re welcome for the hint to take the Best Practices into account :).

Sorry I haven’t had the time yet to look at your module.

Regarding your small issue:

If you would select your save button, you would see its properties in the bottom right corner in Service Studio. One of these properties in called ‘Method’ and in your case it is set to ‘Submit’ in order for the upload widget to work properly.

Now, in the screen action bound to your Save button, you seem to be using an Ajax Refresh element somewhere in your action flow in order to refresh some part of your screen. 

This is why you get the warning in Service Studio, which basically tells you that if the Method of your button is set to Submit and you’re using Ajax Refresh elements in your flow, they will be ignored during code execution at runtime. 

When the Method is set to Submit it affects the Screen Lifecycle in a way that after reaching the End node in your ‘Save’ screen action, the Preparation of your screen will run again and the entire screen will be rendered. These Screen Lifecyles are all explained in detail if you would take the Developing Web Apps Course online in the Learning section of this website.

Anyway, and again I haven’t taken a look at your module, in your case you could probably fix the warning simply by removing the Ajax Refresh element(s). 

If you would want to use the Ajax Refresh element(s), you would need to set the Method of your button to Ajax Submit, but then you would need to separate the upload functionality in a separate screen action with its own button. Again, this is because the Upload widget only works with Method ‘Submit’.

Hope this helps.

Regards,

Nordin



Many thanks to you, I rebuild the functionality step by step. Took some time, as I overlooked the submit-setting, causing the saving error. Now it all works perfectly!