Florian
Posts: 0
Joined: Wed Feb 20, 2013 5:41 pm

image upload to remote server

Hi everybody,

is it possible to upload an image to a remote server (e.g. to a php-script)? I would like to store the uploaded images on my own server. If it is not nativ possible, is there any known workaround for this issue?

Thanks in advance
Florian

Maryna Brodina
Posts: 0
Joined: Thu Apr 05, 2012 7:27 am

image upload to remote server

Hello! Yes, you can do that

Florian
Posts: 0
Joined: Wed Feb 20, 2013 5:41 pm

image upload to remote server

Hi Marina,

thanks for your reply. Can I use this code (with slightly editing).

On the server-side: I would like to process the upload with $_FILES, e.g.

precode
move_uploaded_file($_FILES['userfile']['tmp_name'], $target_path)
/code/pre

precode
function upload() {

Code: Select all

 var serverUrl = 'https://api.tiggzi.com/rest/1/db/files/' + file.name; 

 $.ajax({ 
     type: "POST", 
     beforeSend: function(request) { 
         request.setRequestHeader("X-Tiggzi-Database-Id", FileDB_settings['database_id']),              
         request.setRequestHeader("X-Tiggzi-Session-Token", localStorage.getItem('_sessionToken')), 
         request.setRequestHeader("Content-Type", file.type); 

     }, 
     url: serverUrl, 
     data: file, 
     processData: false, 
     contentType: false, 
     success: function(data) { 

         // OPTIONAL, this is the file name under which the image was stored in database.... 
         // localStorage.setItem('db_file_name', file.name); 

      }, 
     error: function(data) { 
         // do something in case of an error... 
     } 
 }); 

}
/code/pre

Maryna Brodina
Posts: 0
Joined: Thu Apr 05, 2012 7:27 am

image upload to remote server

Yes, if you select image through <input type ="file">

If you get img from camera it would be easier to send that img using REST service (POST request data base64 encoded). Then on server side you don't need to get that img through move_uploaded_file, just into variable. Make decode base64 and save into file.

Florian
Posts: 0
Joined: Wed Feb 20, 2013 5:41 pm

image upload to remote server

Hi Marina,

thanks for your reply.

I followed this simple example (http://help.gotiggr.com/documentation...) to get the image directly from the camera component. Works great. However, what are the next steps? I tryed to map the "imageDataBase64" response from camera service to a local storage variable.

I also added a second button for the upload-service. The upload service has one request parameter (the local storage variable). The upload-service is configured with url (a php-script), method = post, datatype = json, content-type = json.

The php-script on the server-side looks like this:

precode
<?php
define('UPLOAD_DIR', 'upload&#47;');
$img = $_POST['fileselect'];
$img = str_replace('data:image&#47;png;base64,', '', $img);
$img = str_replace(' ', '+', $img);
$data = base64_decode($img);
$file = UPLOAD_DIR &#46; uniqid() &#46; '&#46;png';
$success = file_put_contents($file, $data);
print $success ? $file : 'Unable to save the file&#46;';
?>
/code/pre

Thanks
Florian

Maryna Brodina
Posts: 0
Joined: Thu Apr 05, 2012 7:27 am

image upload to remote server

In your php you wrote $POST['fileselect'], but in your app you send img with name image, so it should be $POST['image'];

Also please check whether you have rights to write to Upload folder. To test set rights for that folder to 777.

Norman Wong
Posts: 0
Joined: Fri Feb 08, 2013 8:04 am

image upload to remote server

file_put_contents created a file, however there have no data in the file

maxkatz
Posts: 0
Joined: Fri Aug 13, 2010 3:24 pm

image upload to remote server

PHP scripting is really outside the scope of our support here.

Carlos Pinto
Posts: 0
Joined: Mon Oct 14, 2013 11:09 am

image upload to remote server

Please excuse me, but how exactly do you call to that button? I do have a submit button but do not know how to link that to the php script on my server. thanks in advance!

Maryna Brodina
Posts: 0
Joined: Thu Apr 05, 2012 7:27 am

image upload to remote server

Hello! Sorry for delay. I'll update.

Return to “Issues”