Forum: Building APIs & Wire Protocol

Post: upload and store photo voltdb php

upload and store photo voltdb php
Ghalia
Dec 18, 2014
Hi,
I want to upload a photo into my database and store it with my php application.
So I start with SQL, I added new attribute to my table:
 profile VARBINARY(1048576),

Now in my php code, I added an input file, and once submetted I execute this code to convert my photo to binary array:



$a = file_get_contents($_FILES['photo']['tmp_name']);
$photo = array();
foreach(str_split($a) as $c)
$photo[] = sprintf("%08b", ord($c));


After that I use my stored procedure to insert data to my table but it dosn't work, when I print the response I got this error:


stdClass Object ( [status] => -2 [appstatus] => -128 [statusstring] => VOLTDB ERROR: PROCEDURE USERS.insert TYPE ERROR FOR PARAMETER 1: org.voltdb.VoltTypeException: tryScalarMakeCompatible: Unable to match parameter array:byte to provided java.lang.String [appstatusstring] => [results] => Array ( ) )
nshi
Dec 18, 2014
Are you sending the photo as a byte array? Can you try sending it as a hex-encoded string to the server?
Ghalia
Dec 18, 2014
I tried : $x=base64_encode($a);

and the result is:
VOLTDB ERROR: PROCEDURE USERS.insert TYPE ERROR FOR PARAMETER 1: java.lang.NumberFormatException: For input string: "IV"

in my sql file I mentioned the attribute " profile VARBINARY(1048576)" should I change it to varchar()??
nshi
Dec 18, 2014
Do you mind sharing the stored procedure signature and the PHP code that calls the stored procedure with us? You can send it to my E-mail if you want. nshi AT voltdb.com

You don't have to change the column type to VARCHAR. The server understands hex-encoded VARBINARY string.
pmartel
Dec 18, 2014
Note that hex encoding is not the same thing as base64 encoding. maybe bin2hex is the function you want?
Ghalia
Dec 18, 2014
thank you, I sent you an email :)
Ghalia
Dec 18, 2014
@pmartel now with bin2hex there's no more error but the field picture is empty???