WOES... Storing image in file system stuff (again)

If you have questions or if you want to share your opinion about Aware IM post your message on this forum
Post Reply
Jaymer
Posts: 2451
Joined: Tue Jan 13, 2015 10:58 am
Location: Tampa, FL
Contact:

WOES... Storing image in file system stuff (again)

Post by Jaymer »

Posted cause its a Ghost Town SLOWWWWW Friday here on the Forum


In my scenario, we need a user to submit a minimum of 4 pictures of his Vehicle.
Front,rear,left,right, with 2 optional pics allowed.
I don't want them to deal with the desktop-UI process of Aware where they add a record, then click to add another, or monkey with the finicky Inline Editing.
This is MOBILE so they can walk around their car, but it can also be done on a PC.
so, I'm creating some placeholder recs for their submission.
A parent record with general details and then a child reference BO with 6 lines in it.
These 6 recs will hold their 4-6 images they submit.
AND, to help them, I added a name for the image so they know which image goes where...
front
rear
left
right
extra1
extra2

PS _ I know what your thinking... why deal with parent child etc. Just create 6 image fields in the main rec and let them assign pics to them.
---> I actually did it this way and had it all working, and then found out about the Image Gallery and that it works on 1 Attribute across many records, vs. 1 record with 6 attributes. I wanted the admin user to be able to see the submitted images using a gallery, to peruse them, etc. Perfect fit for what Vlad has included, except I needed to fit into HIS data structure, hence the re-do. But I digress.......

Remember, there is no IMAGE "yet".
When a process tries to create the "structure" for the submission, if the PATH is empty, it fails.
There cannot be a path yet, cause there is no image.
I tried to set the path to a "no image" file, but when the user finally uploads an Image, it erases the "no image" file that all the other placeholder recs are pointing to, creating more problems.

So, I finally init the path to 'c:\images\Entry1001\' and at least its a path so it doesn't complain.
Everything seems to work fine - a user can upload a real image and THEN it corrects this path.
There is not "no image" file to erase. Life seems good.

So, I'm adding final touches to the Management screen where an admin can view the uploaded images.
Following what happens in the PhotoAlbum, I use the nifty built-in ImageGallery.
EXCEPT it now complains that the default path (which worked to get me this far) is incorrect.
It seems that when the Gallery "starts", it reads in all the images, so it won't even start up unless everything is in order.
Screen Shot 2018-11-29 at 11.22.05 PM.png
Screen Shot 2018-11-29 at 11.22.05 PM.png (142.6 KiB) Viewed 19878 times
The 1st 2 records make it crash.
(You have to scroll the image to the right)
The 2nd line has the bad path, so i tried making it null (see the top line)
Then it gets a different error when its null.
So I made the Path a valid path pointing to my "no image" file.
Then it gets a diff. error because the DOCTYPE doesn't have the filename in it.
Fixed all 3 of those things and the Gallery starts up.

So I have to go back to making a Valid Path before the admin function, or as far back as when I create the data.
Its always something.
Happy Friday
Click Here to see a collection of my tips & hacks on this forum. Or search for "JaymerTip" in the search bar at the top.

Jaymer
Aware Programming & Consulting - Tampa FL
Jaymer
Posts: 2451
Joined: Tue Jan 13, 2015 10:58 am
Location: Tampa, FL
Contact:

Re: WOES... Storing image in file system stuff (again)

Post by Jaymer »

no one is probably dealing with this issue, but someday you might.

I've asked Vlad the following:
Vlad, do you think it would be an easy fix for you to do the following:

WHEN LAUNCHING THE IMAGE GALLERY,
can you ignore an instance where the DOCTYPE field is null?

currently, it gives an error (kendo or the image viewer) because Aware is trying to add an INVALID instance to the gallery.
but if AWARE sees the DOCTYPE value is null, then it can skip that instance.
My thoughts are that, historically, if there was an image, then YES, you'd want to pass it to the gallery.
If my case though, I have the placeholder instance named and waiting for the image, but no image there yet.
So if someone goes to view the gallery in its present state, if an image hasn't been uploaded yet, then launching the gallery CRASHES.
Its just that the Logic for this business case hasn't come up (ie. how can there be an image record, with NO image?) and I'm hoping that Vlad can skip an instance based on the field being null, before passing off a list of record IDs to the Kendo/Lightbox Image gallery.
Click Here to see a collection of my tips & hacks on this forum. Or search for "JaymerTip" in the search bar at the top.

Jaymer
Aware Programming & Consulting - Tampa FL
ACDC
Posts: 1142
Joined: Sat Jun 30, 2007 5:03 pm
Location: California, USA

Re: WOES... Storing image in file system stuff (again)

Post by ACDC »

I would not use the uploaded filename as part of the name stored on disk. I would store the path based on a unique name like Object.ID + somethingguaranteeinguniqueness The fact that the path contains part of the filename may be related to your problem
BenHayat
Posts: 2749
Joined: Thu Dec 23, 2010 5:48 am
Location: Fla, USA
Contact:

Re: WOES... Storing image in file system stuff (again)

Post by BenHayat »

ACDC wrote: The fact that the path contains part of the filename may be related to your problem
The path has to have the filename and extension. Otherwise you get some strange error.

But the name that is uploaded should not be the name used by the app.
I ended up building a sophisticated asset management to use by aware (Picture component) and HTML img tag using URL.
ACDC
Posts: 1142
Joined: Sat Jun 30, 2007 5:03 pm
Location: California, USA

Re: WOES... Storing image in file system stuff (again)

Post by ACDC »

The path has to have the filename and extension. Otherwise, you get some strange error.
My point was to fabricate a new filename with extension ensuring a unique filename for the purpose of the file store and not use the original filename that was uploaded
Jaymer
Posts: 2451
Joined: Tue Jan 13, 2015 10:58 am
Location: Tampa, FL
Contact:

Re: WOES... Storing image in file system stuff (again)

Post by Jaymer »

ACDC wrote: The fact that the path contains part of the filename may be related to your problem
ACDC: Not really sure which problem you are referring to.
I init all lines (before an image is uploaded) to:
c:\webentry\{cust#}\.
What you are seeing (starting with the 3rd row) is how Aware has set the PicPath and DOCTYPE AFTER I properly uploaded an image using the "Select Files" button.
BenHayat wrote: But the name that is uploaded should not be the name used by the app.
But WHY?
You said the PicPath has to match exactly the uploaded file.
Is it just so you could control the filename so in your HTML <img> tag you didn't have weird characters messing up your link?

1. In my case, each set of new files is stored inside a directory created for that customer. So several customers could upload a file name "car1.jpg" and it won't cross-contaminate.
ACDC wrote:My point was to fabricate a new filename with extension ensuring a unique filename for the purpose of the file store and not use the original filename that was uploaded
2. But WHY? except in your case if you are doing 100s+ if images where the filename might already exist, then yes that would be necc. Glad I won't have more than 20 for a given customer, so probably no DUPs.
Click Here to see a collection of my tips & hacks on this forum. Or search for "JaymerTip" in the search bar at the top.

Jaymer
Aware Programming & Consulting - Tampa FL
BenHayat
Posts: 2749
Joined: Thu Dec 23, 2010 5:48 am
Location: Fla, USA
Contact:

Re: WOES... Storing image in file system stuff (again)

Post by BenHayat »

Jaymer wrote: 1. In my case, each set of new files is stored inside a directory created for that customer. So several customers could upload a file name "car1.jpg" and it won't cross-contaminate.
Basically, what ACDC & I were saying, as long as your entire path remains unique, then you're fine. But what if a customer in his folder tries to upload Car1.jpg twice?

Personally, I create a unique 10 digit number and assign it to the image and also store that in my BO as a reference to that image and the full path as "Absolute" since the relative doesn't work properly.
Jaymer
Posts: 2451
Joined: Tue Jan 13, 2015 10:58 am
Location: Tampa, FL
Contact:

Re: WOES... Storing image in file system stuff (again)

Post by Jaymer »

OK, I'm with you guys up to this point.
Lets table the issue of worrying about a filename being unique - No need to rename the user's file.

Moving along...
Here's where I'm up to as of now.
REMEMBER, the point of this post is getting the IMAGE GALLERY to work with my data.

Vlad WAS saying the DOCTYPE (based on the image in the OP) cannot ever be NULL.
Then he modified that statement to this:
"DOCTYPE can be null if DOCDATA is also null, in other words a picture or document is undefined. DOCTYPE CANNOT BE NULL if data is defined.
In your test case you are creating a Photo without an image, so DOCTYPE is allowed to be null."

First, I had to deal with the PATH Attribute, because I'm storing in the FS.
Aware complains if I create a record WITH NO PATH value.
--> So I can just init it to 'C:\WebEntry\10010\.' and that works (where 10010 was a cust ID for this collection)

Here's the difference at RUNTIME between assigning an Image and NOT assigning an image.
Watch this video: https://www.flickr.com/gp/10438488@N00/Z9LRLj
You'll see WHY I don't want to have an image.

SO, If I create the records, here's the way the internal data looks now:
Screen Shot 2018-12-06 at 5.23.13 PM.png
Screen Shot 2018-12-06 at 5.23.13 PM.png (123.61 KiB) Viewed 15399 times
1. I have my Section text for the user
2. I have a Path so Aware doesn't complain an creation time, even though it doesn't point to an image
3. ...but thats OK, cause I don't have an image - DOCTYPE is NULL

Life is good from a data entry standpoint and I like the way the UI works (see video)

Problem is this when running the Image Gallery back on the desktop, to view the user-submitted images:
Screen Shot 2018-12-06 at 5.30.51 PM.png
Screen Shot 2018-12-06 at 5.30.51 PM.png (25.62 KiB) Viewed 15399 times
Awaiting a reply from Vlad about him not sending these invalid records to the Gallery.
4. WHY is the data in this "INVALID" condition? Because I created 6 placeholder records for the images, and lets say the user didn't use the Extra1/Extra2 and only uploaded 4 images. The Paths are correct for the 4, and recs 5 & 6 are not valid, hence the error.
Last edited by Jaymer on Thu Dec 06, 2018 10:49 pm, edited 1 time in total.
Click Here to see a collection of my tips & hacks on this forum. Or search for "JaymerTip" in the search bar at the top.

Jaymer
Aware Programming & Consulting - Tampa FL
BenHayat
Posts: 2749
Joined: Thu Dec 23, 2010 5:48 am
Location: Fla, USA
Contact:

Re: WOES... Storing image in file system stuff (again)

Post by BenHayat »

Jaymer, did you provide extension (jpg, png, etc) at the end of the path?
Jaymer
Posts: 2451
Joined: Tue Jan 13, 2015 10:58 am
Location: Tampa, FL
Contact:

Re: WOES... Storing image in file system stuff (again)

Post by Jaymer »

This is how it looks if Placeholder recs do not get Uploaded (see Rear & Front)
Screen Shot 2018-12-06 at 5.50.51 PM.png
Screen Shot 2018-12-06 at 5.50.51 PM.png (49.81 KiB) Viewed 15396 times
When those 4 recs are passed to the Gallery by Vlad, 2 of them contain bad data, and it craps out.
Click Here to see a collection of my tips & hacks on this forum. Or search for "JaymerTip" in the search bar at the top.

Jaymer
Aware Programming & Consulting - Tampa FL
BenHayat
Posts: 2749
Joined: Thu Dec 23, 2010 5:48 am
Location: Fla, USA
Contact:

Re: WOES... Storing image in file system stuff (again)

Post by BenHayat »

Yes, the REAR & FRONT will crap out. And you have to clean up all the crap... :D
Jaymer
Posts: 2451
Joined: Tue Jan 13, 2015 10:58 am
Location: Tampa, FL
Contact:

Re: WOES... Storing image in file system stuff (again)

Post by Jaymer »

Very hard to clean up those recs.
Here's what I sent to Vlad. This is easy to accomplish in under 10 mins.

Try this with the Demo Photo Album App:

ok, import this photoalbum BSV over a freshly created photoalbum sample BSV

there was 1 change to the menu, to add a query “Photos” in the 1st position

run the Photos query, click the EDIT button on any record

delete the image, save/close

Login as Author - a browse of Albums should appear, with a missing image

Click on ANY image to Launch the Gallery and it will not load



NOW, you would think a solution to this would be to modify the Query… to filter out the Photos with NO IMAGE.
Like this?
FIND AlbumItem WHERE AlbumItem.Photo.DisplayPhoto IS DEFINED
MAKES THIS ERROR: com.bas.basserver.persistence.PersistenceException: Error reading business object. Invalid column name 'DisplayPhoto’.


Here’s what you’ll have to do to modify the Album list:
Edit ALBUM BO
Go to Form: Image Gallery
Edit MAIN
Add the custom filter to the Items attribute: FIND AlbumItem WHERE AlbumItem.Photo.DisplayPhoto IS DEFINED

Running this causes the above Error.


IN CONCLUSION
1) The missing image craps out the Entire Gallery (as I stated in my original Forum post)
2) I cannot SKIP/OMIT the record due to the internal error
3) The issue is MORE complex when you store images in the FS. PhotoAlbum does it the easy way, but all of us users out here are banging our heads and re-creating the wheel just to make this work.


Thats why I asked for you to IGNORE NULL DOCTYPEs when sending a batch of records to the IMAGE GALLERY

jaymer...
Attachments
photoalbum_jaymer.bsv.zip
(74.84 KiB) Downloaded 493 times
Click Here to see a collection of my tips & hacks on this forum. Or search for "JaymerTip" in the search bar at the top.

Jaymer
Aware Programming & Consulting - Tampa FL
PointsWell
Posts: 1458
Joined: Tue Jan 24, 2017 5:51 am
Location: 'Stralya

Re: WOES... Storing image in file system stuff (again)

Post by PointsWell »

Why is your path field being populated if there is no image in the folder? Could you not use a rule to populate the field that contains the path only when the image field is populated?

Similarly if you have a default image in place you could delete that image prior to opening the record rather than using the default edit functionality.

1 - Delete Image
2 - Edit form
3 - User uploads image or
4 - Cancels process - in which case repopulate the field with image and path
Jaymer
Posts: 2451
Joined: Tue Jan 13, 2015 10:58 am
Location: Tampa, FL
Contact:

Re: WOES... Storing image in file system stuff (again)

Post by Jaymer »

Jaymer wrote: IN CONCLUSION
1) The missing image craps out the Entire Gallery (as I stated in my original Forum post)
2) I cannot SKIP/OMIT the record due to the internal error
3) The issue is MORE complex when you store images in the FS. PhotoAlbum does it the easy way, but all of us users out here are banging our heads and re-creating the wheel just to make this work.
jaymer...
This caused an error in the PhotoAlbum sample app. The purpose of this was to SKIP/OMIT any AlbumItem instances where the Image was deleted:
FIND AlbumItem WHERE AlbumItem.Photo.DisplayPhoto IS DEFINED
MAKES THIS ERROR: com.bas.basserver.persistence.PersistenceException: Error reading business object. Invalid column name 'DisplayPhoto’.


#2 - Vlad has ack. this as a BUG to be fixed in next build.
With that fix, I'll be able to add the WHERE clause to skip my PlaceHolder records back on the Admin screen. That will avoid the Gallery crapping out. Life will be good again!
Click Here to see a collection of my tips & hacks on this forum. Or search for "JaymerTip" in the search bar at the top.

Jaymer
Aware Programming & Consulting - Tampa FL
Post Reply