multiple image uploader

197 views
Skip to first unread message

James Roberts

unread,
May 21, 2014, 3:54:13 PM5/21/14
to xata...@googlegroups.com
Hi, 

I have a client who'd like to be able to select multiple images at one time, and upload them, tying them to the record they are creating / editing.  I currently have it set up so they can select and add images one-by-one, but that's not good enough for this client.  

My question is - how difficult would this be?  I suspect it's quite difficult, but figured I'd ask in case there are any shortcuts or strategies that might make this relatively straightforward.  

Currently my idea is to create a separate application that allows them to upload the images and associate them with an existing record.  Not the best, but I don't want to hack up xataface and risk breaking other functionality.  

-Jim

Steve Hannah

unread,
May 21, 2014, 4:16:11 PM5/21/14
to James Roberts, xata...@googlegroups.com
I don't current'y have a widget that supports this.  The closest thing is using the ajax uploader with the grid widget to select multiple images in the same form.

Writing a widget that would allow multiple images to be uploaded at once wouldn't be all that difficult.  E.g. using a javascript library like 
This already supports multi-file uploads and includes sample PHP scripts to show you how to handle the uploads.  The ajax upload module actually uses this jQuery library for its uploads, but I have it set to only allow single uploads at a time because that worked more easily with the model.

Writing a widget isn't that difficult, but I haven't written any comprehensive guides on how to do it yet, so you'd have to look at an existing widget (like depselect or ajax upload) to see how it is done.

Alternatively, an easier approach might be to just make a custom action and incorporate this jquery library (or similar one) to handle the upload.

Steve
--
Steve Hannah
Web Lite Solutions Corp.

Edward DeFord

unread,
Jul 7, 2014, 9:34:38 AM7/7/14
to xata...@googlegroups.com, j...@robertswebforge.com
how do I use the Ajax_uploader with the grid widget?  I am also trying to associate multiple file uploads with a single record.  I just don't know how to get them to work together.  Can you show me an example?

Steve Hannah

unread,
Jul 7, 2014, 4:57:32 PM7/7/14
to Edward DeFord, xata...@googlegroups.com, James Roberts
Start by setting up a table where you store one uploaded file per row.  E.g. You might have a table called "files" with fields "file_id", "file", "file_mimetype".

Make the "file" field a container field and set the widget to be ajaxupload.

Confirm that this works by using the new record and edit forms directly on this table.

Next create a relationship from the table that will have the grid widget, to your files table.

Suppose this table is called messages, and the relationship is called "attachments".

Your relationship definition might look something like:

[attachments]
    message_attachments.message_id="$message_id"
    message_attachments.file_id=files.file_id


In your messages table, you create a transient field for your grid widget.

[attachments]
    transient=1
    widget:type=grid
    relationship=attachments
    widget:columns=file

This should be all you need to do.


Steve

Edward DeFord

unread,
Jul 8, 2014, 1:51:42 PM7/8/14
to xata...@googlegroups.com, e...@nantasketwebdesign.com, j...@robertswebforge.com
Thanks Steve that was very helpful. I've almost got it working now. a few questions... I have a table 'assetshub' that contains the records, I created a table 'images' and defined the relationship between them in both the tables/assetshub folder and the tables/images folder.  Is it really necessary to define the relationship in both places? Also I have another column in the images table called 'timestamp', I would like to add a creation date and insert it here.  It doesn't seem to want to work for me.... why?

Steve Hannah

unread,
Jul 8, 2014, 2:09:02 PM7/8/14
to Edward DeFord, xata...@googlegroups.com, James Roberts
 Is it really necessary to define the relationship in both places?
Relationships defined in xataface are one way only.  So yes.  If you want an relationship from A to B and a relationship from B to A, you need to define it in both tables.
 
Also I have another column in the images table called 'timestamp', I would like to add a creation date and insert it here.  It doesn't seem to want to work for me.... why?
What have you tried so far to make it add the date.  Did you try using
timestamp=insert 
in the fields.ini file for that field?

Steve

Edward DeFord

unread,
Jul 10, 2014, 2:00:55 PM7/10/14
to xata...@googlegroups.com, e...@nantasketwebdesign.com, j...@robertswebforge.com
Yes that is exactly what I did.

[creationdate]
timestamp=insert
widget:type=hidden

I changed the column name to 'creationdate' to see if that made any difference, it did not.  I also tried changing widget: type= static to see if I could view it but no result either.

Why won't it write to that column but it will write to the other columns... very strange.

Steve Hannah

unread,
Jul 10, 2014, 2:04:22 PM7/10/14
to Edward DeFord, xata...@googlegroups.com, James Roberts
Try changing it to a DATETIME field instead of a TIMESTAMP field.

Steve

Edward DeFord

unread,
Jul 11, 2014, 7:56:21 AM7/11/14
to xata...@googlegroups.com, e...@nantasketwebdesign.com, j...@robertswebforge.com
Thank you Steve, that was just the little piece of information I needed to get this working.  I'm enjoying working with Xataface, once I get the hang of it I think it will save me a lot of time.

Edward DeFord

unread,
Jul 11, 2014, 12:42:03 PM7/11/14
to xata...@googlegroups.com, e...@nantasketwebdesign.com, j...@robertswebforge.com
One last little thing, now that i have created my images table I would like to make the first one the logo image for that record.  Is there a trick to doing that?  I tried the 'logo=1' but that didn't do it.  What else can I try.

Steve Hannah

unread,
Jul 11, 2014, 2:26:42 PM7/11/14
to Edward DeFord, James Roberts, xata...@googlegroups.com

You'll want to make a grafted field for this.  Then assign that field as the logo.  You may also need to mark that field as a container field or override the HTML value to display an image.....

It's been a while since I've done something like this so there might be other details I have forgotten.

Steve

Edward DeFord

unread,
Jul 14, 2014, 11:58:58 AM7/14/14
to xata...@googlegroups.com, e...@nantasketwebdesign.com, j...@robertswebforge.com
Thanks Steve, that worked out just great. I created the HTML override no problem. but I have a new bug.

In using the ajax_upload with the grid widget it keeps creating multiple copies of the same record and displaying them in the edit form and in the list. I don't quiet understand what it is doing..very strange.  Any more good advice?

Steve Hannah

unread,
Jul 14, 2014, 12:14:29 PM7/14/14
to Edward DeFord, xata...@googlegroups.com, James Roberts
Are you working off the GitHub version or the release on Sourceforge?  I think there was a bug like this in 2.0.3 that has since been fixed in GitHub.

Edward DeFord

unread,
Jul 15, 2014, 9:51:12 AM7/15/14
to xata...@googlegroups.com, e...@nantasketwebdesign.com, j...@robertswebforge.com
I did as you suggested and uploaded xataface from GitHub and installed it on my server.  this did not seem to have any effect at all on my ajax_upload grid, I still see multiple copies of each record and an extra upload form and a broken link as well.  It also drops all the information in the rest of the form fields.  ONE REALLY NASTY BUG.

I'm at a stand still, any advice you could give me on how to proceed would be helpful.  What do you think the problem is?

Edward DeFord

unread,
Jul 15, 2014, 10:18:15 AM7/15/14
to xata...@googlegroups.com, e...@nantasketwebdesign.com, j...@robertswebforge.com
More info...

ajax_upload/grid is creating an empty record in my main table 'assetshub' as well as giving me duplicates of each photo I upload.  I'm still not sure what is causing this... any ideas?

Steve Hannah

unread,
Jul 16, 2014, 2:01:50 AM7/16/14
to Edward DeFord, xata...@googlegroups.com, James Roberts
Can you provide a minimal example (table defs, fields.ini, relationships.ini) to reproduce this problem?  

Steve

Edward DeFord

unread,
Jul 16, 2014, 8:26:25 AM7/16/14
to xata...@googlegroups.com, e...@nantasketwebdesign.com, j...@robertswebforge.com
Thanks for taking the time to look into this with me.

I have two tables 'secureassetshub' and 'images'.

CREATE TABLE IF NOT EXISTS `assetshub` (
  `id` int(200) NOT NULL AUTO_INCREMENT,
  `item_name` varchar(128) NOT NULL,
  `UserID` varchar(32) DEFAULT NULL,
  `location` varchar(255) NOT NULL,
  `descr` text NOT NULL,
  `condition` text NOT NULL,
  `stordate` varchar(32) DEFAULT NULL,
  `dest` varchar(255) DEFAULT NULL,
  `ival` varchar(255) NOT NULL,
  `wrhouse` varchar(255) NOT NULL,
  `lot` varchar(60) NOT NULL,
  `icolor` varchar(32) DEFAULT NULL,
  `itag` varchar(32) DEFAULT NULL,
  `piece` varchar(32) DEFAULT NULL,
  `dimens` varchar(255) DEFAULT NULL,
  `assettime` datetime DEFAULT NULL,
  PRIMARY KEY (`id`)
) ENGINE=MyISAM  DEFAULT CHARSET=latin1 AUTO_INCREMENT=112 ;


CREATE TABLE IF NOT EXISTS `images` (
  `assetID` int(200) NOT NULL,
  `creationdate` datetime DEFAULT NULL,
  `reImage` varchar(200) NOT NULL,
  `imageID` int(200) NOT NULL AUTO_INCREMENT,
  PRIMARY KEY (`imageID`)
) ENGINE=MyISAM  DEFAULT CHARSET=utf8 AUTO_INCREMENT=56 ;

My assetshub/fields.ini looks like this...

__sql__="SELECT assetshub.*,images.reImage FROM assetshub LEFT JOIN images ON assetshub.id=images.assetID"
[reImage]
logo=1
savepath="photos"
Type=container
url="photos"
allowed_extensions = "gif,jpg,jpeg,png"
[assetImages]
Type=container
widget:label = "Images"
logo=1
transient=1
relationship=otherImages
widget:type=grid
widget:columns="reImage,assetID"

my assetshub/relationships.ini looks like this.  I also defined this relationship in images/relationships.ini.

[otherImages]
__sql__= "SELECT images.reImage,images.assetID,images.creationdate,assetshub.id FROM images,assetshub WHERE images.assetID = assetshub.id AND assetshub.id = '$id'"

my images/fields.ini looks like this...

[reImage]
transient=1
relationship=otherImages
logo=1
Type=container
widget:type=ajax_upload
savepath="photos"
url="photos"
allowed_extensions = "gif,jpg,jpeg,png"
[imageID]
widget:type=static
[creationdate]
timestamp=insert
widget:type=hidden
[assetID]
widget:type=static

I can't explain the behavior I'm experiencing, it  creates a blank record in my 'assetshub' database. it also displays duplicate records of the images.  if I try and delete the duplicates it will delete the entire record.

I hope you can shed some light on this issue.

Thanks again for your help.

Edward DeFord

unread,
Jul 21, 2014, 2:12:44 PM7/21/14
to xata...@googlegroups.com, e...@nantasketwebdesign.com, j...@robertswebforge.com
I also tried downloading and installing the latest ajax_upload files, this had no efferct.

Andy Reid

unread,
Oct 16, 2015, 7:19:59 AM10/16/15
to Xataface, e...@nantasketwebdesign.com, j...@robertswebforge.com
I have a very similar problem with a subsequent drag and drop file overwriting all the previous child files- did you ever get past this?  I've just posted a query, then noticed this thread (should have looked first... slap!)

Andy
Reply all
Reply to author
Forward
0 new messages