cancel
Showing results for 
Search instead for 
Did you mean: 

Receive an image from http post

Former Member
0 Kudos
2,139

With php I can simply write a short snippet to receive an image. Like this:

$uploaddir = 'upload/';

$uploadfile = $uploaddir . basename( $_FILES['uploaded_file']['name']);
if(move_uploaded_file($_FILES['uploaded_file']['tmp_name'], $uploadfile) )
{
    echo "success";
} else
{
    echo $uploadfile;
}

So my question is, does anyone know how to get this functionality with a SQLAnywhere webservice? How can I access Http variables like the $_FILES (php)?

I want to send a captured image from an android device to a SQLAnywhere webservice.

Thanks for your help! Regards

Accepted Solutions (1)

Accepted Solutions (1)

MarkCulp
Participant

Please see the example called "gallery.sql" that comes with the SQL Anyhere install.

The basic idea is that you can get all of the information that you need from the POST request to the server by using the HTTP_VARIABLE() function.

An excerpt from the gallery.sql example:

declare v_name  varchar(250);
declare v_type  varchar(50);
declare v_image long binary;
declare i       int;
[...snip...]
set v_name  = http_variable( 'image', NULL, 'Content-Disposition' );
set v_type  = http_variable( 'image', NULL, 'Content-Type' );
set v_image = http_variable( 'image', NULL, '@BINARY' );
[...snip...]
-- pick out the filename from the Content-Disposition
set i = locate( v_name, 'filename=' );
set v_name = substr( v_name, i+10 );
set i = locate( v_name, '"' );
set v_name = left( v_name, i-1 );

The v_name variable contains the file name that was uploaded and v_image contains the actual image content.

The post_data.sql and put_data.sql examples may also be of some help.

HTH

Answers (0)