Icon View Thread

The following is the text of the current message along with any replies.
Messages 1 to 6 of 6 total
Thread file upload as part of a larger form post
Wed, Nov 26 2014 4:18 PMPermanent Link

Stephen Barker

I have a form which is for editing a product record. The TEdits are connected to a TDataSet, and named the same as the fields so that the SubmitForm takes care of the encoding for me. This is POSTed to my own server and the database is updated, which works fine.

The problem is for a field containing a string URL to an image for each product. If I use a TEdit control to edit this string it works as expected. If I use a TFileUploadButton, then I can't initialise it to it's existing value. However, if the user selects a new image then it uploads and gets assigned ok. So for creating new products or for selecting images for existing products it works fine, it just doesn't work for passing through the unchanged image URL for existing products that may have had some other fields modified.

I thought of having a pair of TEdit and TFileUploadButtons on the form and renaming them on the fly so that only one of them was named after the underlying TField at any point, but that failed.

Can someone help me locate in the framework the point at which the contents of a file about to be uploaded are encoded and added into the content payload? I may have to study this a bit more.

Another option would be to make the image file uploading happen on a completely separate dialog, but I'd rather not.

Thanks,
Steve
Thu, Nov 27 2014 4:17 AMPermanent Link

Matthew Jones

Stephen Barker wrote:

> The problem is for a field containing a string URL to an image for
> each product. If I use a TEdit control to edit this string it works
> as expected. If I use a TFileUploadButton, then I can't initialise it
> to it's existing value. However, if the user selects a new image then
> it uploads and gets assigned ok. So for creating new products or for


Hmm, I don't know enough about the image upload, but how can that give
you a URL? The URL is where to get the image on the internet. The image
upload is surely a transfer from the local browser to your server, and
doesn't thereby get a new URL or anything.

--

Matthew Jones
Thu, Nov 27 2014 5:56 AMPermanent Link

Stephen Barker

"Matthew Jones" wrote:

Hmm, I don't know enough about the image upload, but how can that give
you a URL? The URL is where to get the image on the internet. The image
upload is surely a transfer from the local browser to your server, and
doesn't thereby get a new URL or anything.

Hi Matthew,
That's not part of the problem, but how this works is my server stores the uploaded file into a predetermined folder (a site setting), then converts this physical path into a relative URL relative to the site's root, and stores that in the string field.

Steve
Fri, Nov 28 2014 6:44 AMPermanent Link

Tim Young [Elevate Software]

Elevate Software, Inc.

Avatar

Email timyoung@elevatesoft.com

Stephen,

<< I thought of having a pair of TEdit and TFileUploadButtons on the form
and renaming them on the fly so that only one of them was named after the
underlying TField at any point, but that failed. >>

You're close - use a TEdit with a TFileUploadButton, and then use this
event:


>
> Can someone help me locate in the framework the point at which the
> contents of a file about to be uploaded are encoded and added into the
> content payload? I may have to study this a bit more.
>
> Another option would be to make the image file uploading happen on a
> completely separate dialog, but I'd rather not.
>
> Thanks,
> Steve
>
Fri, Nov 28 2014 6:46 AMPermanent Link

Tim Young [Elevate Software]

Elevate Software, Inc.

Avatar

Email timyoung@elevatesoft.com

Stephen,

Damn newsreader posted my message too quickly:

Use this event:

http://www.elevatesoft.com/manual?action=viewevent&id=ewb1&comp=TFileUploadButton&event=OnChange

to detect when the file upload button changes it's contents, and then update
the TEdit accordingly.  Then, send both the TEdit and the TFileUploadButton
to the back-end, and have the back-end determine what to do based upon the
contents of the TFileUploadButton's incoming name:  if the value isn't there
for the TFileUploadButton control, then use the TEdit control's value.

Tim Young
Elevate Software
www.elevatesoft.com
Sat, Nov 29 2014 8:38 PMPermanent Link

Stephen Barker

Thanks Tim,

I've already made the file upload into a separate form for now, but I might revisit it at a later stage.

The problem with your suggestion is the back end expects the form fields to be named the same as the table fields so I can't have both a TEdit and a TFileUploadButton named the same. I'd need to do some redesign of the back end which is generic at the moment and not specific to this site, to handle such pairs of fields.

That's why I was originally interested in looking at the framework source in this area of writing the uploaded file content into the multipart stream - to see if there was a way I could automatically split it into 2 fields there, to pick up the uploaded file but pass through the text field as a normal field.

cheers,
Steve
Image