« Return to Thread: Multiple picture uploads

Re: Multiple picture uploads

by kjelle :: Rate this Message:

Reply to Author | View in Thread

I had exactly the same problem but I now solved it and here is how: I created a form with 5 file-upload fields in the form. Submitting the form to 4D, catch the body with 'Get http body($body) and execute the blob to picture command. The Blob can't be analyzed but the picture variable can. I saved the picture to disk (write picture file) and the opened the file in Text-edit. As I know the name of the web-form fields and discovered that directly at the end of every image in the variable there was a "-----WebKitFormBoundary..." (I use Safari maybe other things from other browsers) I then could get the position in the blob with 'AP Find in Blob' from the plug-in API pack (Shareware). Rest is easy. copy to blob(from start-original; to start-copy; tobefore position of "---...";number of bytes) blob to picture once again and you have the new image in the new picture variable. write picture file or whatever with the new variable. Delete from blob (the old blob) the bytes you already have in the new picture variable.

Put everything in a loop that loops as many times as there are pictures in the form.

Hope it helps.


michel-45 wrote:
Hi everyone,

I am trying to upload more than one picture file from a web page. I am  
using the example code given on the 4D site:

If (BLOB size(picBLOB)>0)  ` did user select a file for uploading?
        C_STRING(255;$fileHeader)
        $offset:=0  ` BLOB to text requires a variable for the offset parameter
        $fileHeader:=BLOB to text(picBLOB;Text without length ;$offset;255)
        $fileNameBegin:=Position("filename=";$fileHeader)+10
        For ($i;$fileNameBegin;255)
                If ($fileHeader≤$i≥=Char(Double quote ))
                        $fileNameEnd:=$i
                        $i:=255
                End if
        End for
        $fileName:=Substring($fileHeader;$fileNameBegin;$fileNameEnd-
$fileNameBegin)
        $contentTypeBegin:=Position("Content-Type:";$fileHeader)+14
        For ($i;$contentTypeBegin;255)
                If ($fileHeader≤$i≥=Char(Carriage return ))
                        $contentTypeEnd:=$i
                        $i:=255
                End if
        End for
        contentType:=Substring($fileHeader;$contentTypeBegin;$contentTypeEnd-
$contentTypeBegin)
        DELETE FROM BLOB(picBLOB;0;$contentTypeEnd+3)
        $err:=AP Read picture BLOB (picBLOB;imageVar)
End if

This works fine for uploading one picture but seems to not work on  
multiple pictures. I have identical code right after this code but  
substituted picBLOB with picBLOB1. Using TRACE the picBLOB variable  
gives the picture size but picBLOB1 variable always seems to display  
the picture file name.

Anyone know how to get around this?

Thanks,
Michel.
**********************************************************************
4D Basics hosted by 4D, Inc.                       http://www.4D.com/

Power, Speed, Scalability is 4D v11 SQL
Upgrade today! <http://store.4ddepot.com/>

To Unsubscribe:                        mailto:4DBasics-off@info.4D.com
**********************************************************************

 « Return to Thread: Multiple picture uploads