Handling images and other files

mod_harbour is an Apache module that allows to run PRGs directly on the web !!!
Post Reply
User avatar
ricbarraes
Posts: 49
Joined: Tue Jun 30, 2015 2:26 am
Location: Brazil

Handling images and other files

Post by ricbarraes »

Hey everybory, happy new year!

I'm having some trouble when trying to manipulate image files, if anybody could tell what I'm possibly doing wrong, I'll be extremely grateful!

Situation 1:

I got a desktop application that is storing image files inside a MySQL database as a BLOB field.
So I need to get this content from my database and convert it to an JPG file and display inside my web application.
the first step is OK, I'm getting the right content from my database which, in this case, is a string with the BLOB content. Now, the problem is that the convertion to a JPG file is not working. That's what I'm trying to do:

Code: Select all

memowrit("C:\test\teste.jpg",cImage)
*cImage is the BLOB content retrieved from de database.

what is happening right here is that the BLOB content is not being coverted to a JPG file, instead it's saving the string content like a TEXT file but with the JPG extension.

Situation 2:

the user of my web application needs to send a file to my webservice (both developed with mod_harbour), so that my webservice must get this file and store it locally.

I know there's a way of sending this file inside my HTTP request, but I don't know exactly the headers and data that should go inside of it. Does anybody knows?

And after sending it, I don't really know exactly how to get this file from the request using Mercury and mod_harbour, is there any sample that explains how to do it?

Thanks!
Sds,
Ricardo Arraes
ricardo@vfatec.com.br
User avatar
Otto
Posts: 4470
Joined: Fri Oct 07, 2005 7:07 pm
Contact:

Re: Handling images and other files

Post by Otto »

Hello Ricardo,

Situation 1:
Here is a program Mr. Rao gave us during the Fivewin-meeting in Sillian.
Image


https://mybergland.com/fwforum/bas64img.zip

1. BAS64IMG.PRG
2. BAS64IMG.EXE // you can readily use this to test
// image files
3. b64img01.txt
4. b64img02.txt
5. b64img03.txt
6. b64img04.txt
7. b64img05.txt
8. b64img06.txt
9. b64img07.txt

This program extracts any image png, bmp, jpg, gif, etc and not limited to png.

We can read from a file or paste from clipboard.

You can cross-check the correctness of the results at
https://codebeautify.org/base64-to-image-converter

I have tested many types of images.


At the heart of this program the main conversion function:

static function Blob2Image( cText )

local nAt
local lValid := .t.

if ( nAt := AT( "base64", cText ) ) > 0
cText := SubStr( cText, nAt + 6 )
if Left( cText, 1 ) == ","
cText := SubStr( cText, 2 )
elseif UPPER( Left( cText, 3 ) ) == "%2C"
cText := SubStr( cText, 4 )
else
lValid := .f.
endif
if lValid
do while Right( cText, 1 ) $ [>)"]
cText := Left( cText, Len( cText ) - 1 )
enddo
cImage := HB_BASE64DECODE( cText )
cImgType := MemoryBufferType( cImage )
endif
else
lValid := .f.
endif

if !lValid
cImage := ""
cImgType := "INVALID"
endif
return cImage

Situation 2:

have you looked into the TWeb sample button-upload.prg.
This is working fine for me.
I extracted the functions that I can use them without installing TWeb.
Here is my test:
https://mybergland.com/fwforum/uploadphoto.zip

Best regards,
Otto
********************************************************************
mod harbour - Vamos a la conquista de la Web
modharbour.org

********************************************************************
User avatar
Otto
Posts: 4470
Joined: Fri Oct 07, 2005 7:07 pm
Contact:

Re: Handling images and other files

Post by Otto »

Ricardo,
I made a test from smartphone. :-)
Image
Best regards,
Otto
********************************************************************
mod harbour - Vamos a la conquista de la Web
modharbour.org

********************************************************************
Post Reply