APIs: POST any local file to a php server

12,677 views
Skip to first unread message

Scott Ferguson

unread,
Sep 30, 2012, 5:59:29 PM9/30/12
to app-inventor-de...@googlegroups.com

This test configuration works for me, but I cannot guarantee it will work on other servers than with the hosting service I use (000webhost.com). Oddly enough it requires no header information to be entered from App Inventor, yet allows use of the Web component's PostFile block with the added bonus that I did not have to figure out how to tell the server what type of data I was sending in a Content-Type entry. It is just a data stream that the server captures and converts back into a file. The php $_GET variable works also to pass the file name for the destination file as a switch on the URL.

Well, here it is...
web_post_file_test.zip
postfiletest.php
Message has been deleted

Zach Soflin

unread,
Jan 28, 2013, 4:51:50 PM1/28/13
to app-inventor-de...@googlegroups.com
any ideas why I would get a 403 forbidden and 404 Not found when using this? have been trying for hours and can't get the file to upload. I suspect it has something to do with the data stream, but am not experienced in php. Any ideas?

Scott Ferguson

unread,
Jan 30, 2013, 3:05:54 AM1/30/13
to app-inventor-de...@googlegroups.com
Make sure that your permissions to the directory folder on the server and to the file being written to allow write access and that the php script has execute access. Other than that, I don't know. I posted a question once on the PHP forum but got no response whatsoever so don't expect much help there.
---sfs
Message has been deleted

Zach Soflin

unread,
Feb 6, 2013, 10:18:03 AM2/6/13
to app-inventor-de...@googlegroups.com
Thanks for the quick reply Scott, I must have missed the alert email because I just saw your response, sorry. you were right, I use Hostgator and they had to whitelist the script for it to work. I now can send the POST request from App Inventor, and get the file to show up in the directory. The problem is the file is empty. Seems the data stream isn't working. Any ideas? did you have this problem? Thanks again for the help, I have been scouring the web for an answer to this. 
-Zach

Taifun

unread,
Feb 6, 2013, 10:50:46 AM2/6/13
to app-inventor-de...@googlegroups.com
see here http://php.net/manual/en/wrappers.php.php
as it seems to be, always_populate_raw_post_data is set to false on your server. You can find that out, with the following script:

<?php
phpinfo();
?>

but some web hoster do not allow to change that parameter...
see also here http://stackoverflow.com/questions/9907896/what-are-the-alternatives-for-php-input-and-http-raw-post-data-when-file-get

let us know if you get it running...
probably I should try that http://stackoverflow.com/a/10320453/1545993 myself too if I find some time?
Taifun


php://input

php://input is a read-only stream that allows you to read raw data from the request body. In the case of POST requests, it is preferable to use php://input instead of $HTTP_RAW_POST_DATA as it does not depend on special php.ini directives. Moreover, for those cases where $HTTP_RAW_POST_DATA is not populated by default, it is a potentially less memory intensive alternative to activating always_populate_raw_post_data. php://input is not available with enctype="multipart/form-data".


Zach Soflin

unread,
Feb 6, 2013, 12:06:19 PM2/6/13
to app-inventor-de...@googlegroups.com
Thanks for the quick reply Taifun, 
Hum... I contacted HostGator and got always_populate_raw_post_data enabled. Using phpinfo() i can see that it is enabled. I am still getting a blank file in my directory with no errors anywhere. I guess the only problem showing is when I hit the "Post" button on Scotts example, It gives me the error "1104 unable to Post file..." but if I push the button again the response reads "file transfer completed".and the blank file shows up on my web server. Any other ideas? This is stumping me.
-Zach

Zach Soflin

unread,
Feb 6, 2013, 12:42:55 PM2/6/13
to app-inventor-de...@googlegroups.com
GOT IT! wow that took way too long, but I found a post from Scott that said to try swapping out php://input with php://stdin. It worked! So anyone using host gator make sure to enable always_populate_raw_post_data by contacting customer service and begging and pleading (they are pretty good about it). Then using Scotts example but swap out php://input for php://stdin. Thanks for the direction you two.
-Zach

Scott Ferguson

unread,
Feb 6, 2013, 9:29:11 PM2/6/13
to app-inventor-de...@googlegroups.com
Glad you got it working, Zach! And thanks Taifun :)
---sfs

Taifun

unread,
Feb 8, 2013, 12:55:38 PM2/8/13
to app-inventor-de...@googlegroups.com
I now played around with the workaround mentioned above and put together an example here http://puravidaapps.com/postfile.php
This workaround is useful, if you can't set the flag always_populate_raw_post_data = on on your server
Taifun

Scott Ferguson

unread,
Feb 9, 2013, 4:19:36 PM2/9/13
to app-inventor-de...@googlegroups.com
Very nice -- and that Pear package provides the workaround on the PHP end.
---sfs

Zach Soflin

unread,
Feb 11, 2013, 7:46:49 PM2/11/13
to app-inventor-de...@googlegroups.com
Hi again,
Do either of you know if you can detect the error 1104 when it pops up? I essentially have this script uploading the image every time the camera takes a picture. It works 75% of the time, but sometimes I get an error bubble that pops up for a few seconds then disappears  it says, "error 1104" and then says it wasn't able to POST the file. I would like to be able to detect it so I can have the app try again. Any ideas?
-Zach

Taifun

unread,
Feb 11, 2013, 8:22:25 PM2/11/13
to app-inventor-de...@googlegroups.com
you can try to catch the error with the Screen.ErrorOcurred block
Taifun


Am Montag, 11. Februar 2013 18:46:49 UTC-6 schrieb Zach Soflin:
Hi again,
Do either of you know if you can detect the error 1104 when it pops up? I essentially have this script uploading the image every time the camera takes a picture. It works 75% of the time, but sometimes I get an error bubble that pops up for a few seconds then disappears  it says, "error 1104" and then says it wasn't able to POST the file. I would like to be able to detect it so I can have the app try again. Any ideas?
-Zach

On Wednesday, February 6, 2013 11:42:55 AM UTC-6, Zach Soflin wrote:
GOT IT! wow that took way too long, but I found a post from Scott that said to try swapping out php://input with php://stdin. It worked! So anyone using host gator make sure to enable always_populate_raw_post_data by contacting customer service and begging and pleading (they are pretty good about it). Then using Scotts example but swap out php://input for php://stdin. Thanks for the direction you two.
-Zach

On Wednesday, February 6, 2013 11:06:19 AM UTC-6, Zach Soflin wrote:
Thanks for the quick reply Taifun, 
Hum... I contacted HostGator and got always_populate_raw_post_data enabled. Using phpinfo() i can see that it is enabled. I am still getting a blank file in my directory with no errors anywhere. I guess the only problem showing is when I hit the "Post" button on Scotts example, It gives me the error "1104 unable to Post file..." but if I push the button again the response reads "file transfer completed".and the blank file shows up on my web server. Any other ideas? This is stumping me.
-Zach

On Wednesday, February 6, 2013 9:50:46 AM UTC-6, Taifun wrotey to

Zach Soflin

unread,
Feb 12, 2013, 11:25:59 PM2/12/13
to app-inventor-de...@googlegroups.com
Perfect, thanks, exactly what I was looking for!
-Zach

Simon Carr

unread,
Mar 18, 2013, 3:26:07 PM3/18/13
to app-inventor-de...@googlegroups.com
Hi Scott,

Thank you for this. I have a problem however. My server just saves an empty (0kb) image file. Any ideas what I might be doing wrong?

Simon

Taifun

unread,
Mar 18, 2013, 3:37:44 PM3/18/13
to app-inventor-de...@googlegroups.com
are you able to set the flag always_populate_raw_post_data = on ?
Taifun

Simon Carr

unread,
Mar 18, 2013, 3:53:41 PM3/18/13
to app-inventor-de...@googlegroups.com
Yep, I already did that, then restarted apache and checked my php.ini which says it is on.

I have tried php://input, php://stdin and $HTTP_RAW_POST_DATA

I tried echo'ing out the value of $data but it is empty so I am not sure if my phone is even sending any data in the post. I am using the unaltered provided by your self. I just changed the URL and the get variable from filename to fn to suit scott's PHP script.

I am using a Samsung Note 2 and am using a VPS server hosted by 123-reg.

Here is the php script

<?PHP
   $data = file_get_contents('php://input');
echo $data;
   if (!(file_put_contents($_GET['fn'],$data) === FALSE)) echo "File xfer completed."; // file could be empty, though
   else echo "File xfer failed.";
?>


Simon

Taifun

unread,
Mar 18, 2013, 4:50:22 PM3/18/13
to app-inventor-de...@googlegroups.com

Scott Ferguson

unread,
Mar 18, 2013, 6:24:25 PM3/18/13
to app-inventor-de...@googlegroups.com
Have you tried Content-Type image/png or image/jpg etc. for your Headers?
---sfs

Péter Simon

unread,
Nov 3, 2013, 5:37:00 AM11/3/13
to app-inventor-de...@googlegroups.com
hey, can u help me, how can i set the flag always_populate_raw_post_data to on on my server?  if u can please explain this for me like u can explain this to a 5 yrs old child.. :D 

Scott Ferguson

unread,
Nov 3, 2013, 6:03:14 AM11/3/13
to app-inventor-de...@googlegroups.com
You could try this workaround at the top of a php script: http://www.rdlt.com/always_populate_raw_post_data-disabled-heres-a-workaround.html
This person set the flag to on in his script: http://pastebin.com/qvF6PeyR
Example entry in php.ini:
always_populate_raw_post_data = On
---sfs

Péter Simon

unread,
Nov 3, 2013, 8:09:21 AM11/3/13
to app-inventor-de...@googlegroups.com
thanks for the fast reply! now i found an ftp server with anonymus acces, but my app isnt working. can u tell me Scott what is the problem? :)
help.jpg

Taifun

unread,
Nov 3, 2013, 9:15:37 AM11/3/13
to app-inventor-de...@googlegroups.com
there is no ftp component in App Inventor, star issue 1111 https://code.google.com/p/app-inventor-for-android/issues/detail?id=1111
you will need a php script on the server to be able to upload a file
In case you can't set the flag always_populate_raw_post_data = on on your server, you can try my workaround http://puravidaapps.com/postfile.php
 Taifun

Kevin Darden

unread,
Nov 16, 2013, 2:38:19 PM11/16/13
to app-inventor-de...@googlegroups.com
What is the file being written to?  Do I need to create a file like Get Images.php under the public_html directory? Would this then be the file?  Do I need to modify something in the designer to match this? Do I modify something in the code block to match this?


On Wednesday, January 30, 2013 2:05:54 AM UTC-6, Scott Ferguson wrote:

Scott Ferguson

unread,
Nov 17, 2013, 7:12:48 AM11/17/13
to app-inventor-de...@googlegroups.com
I have requested that you attach the current zip project and insert the php script text in your other post. Thanks.
---Scott

Jon Reneberg

unread,
Dec 15, 2013, 5:54:24 PM12/15/13
to app-inventor-de...@googlegroups.com
The file name of the file on your Android device cannot have a space in it, or it will stop at the space.  Some quick code could replace spaces with underscores.

I am also getting the full file name saved with 0kb.  Is this a permission issue?  How would I find out if my Android device is sending the full file rather than just the name?

Taifun

unread,
Dec 15, 2013, 6:02:27 PM12/15/13
to app-inventor-de...@googlegroups.com
I am also getting the full file name saved with 0kb.  Is this a permission issue?  
in the php script try to replace php://input by php://stdin

 How would I find out if my Android device is sending the full file rather than just the name?
the postfile block sends a file and not a text
probably that workaround can help, too: http://puravidaapps.com/postfile.php 
Taifun

Jon Reneberg

unread,
Dec 15, 2013, 6:37:20 PM12/15/13
to app-inventor-de...@googlegroups.com


On Sunday, December 15, 2013 6:02:27 PM UTC-5, Taifun wrote:
I am also getting the full file name saved with 0kb.  Is this a permission issue?  
in the php script try to replace php://input by php://stdin

Hmmm...  Still get the file with 0kb.
When I press the "Post" button, it takes 90 seconds or so before I get the "File xfer completed." message which leads me to believe that the Android app is uploading the full image, but it's somehow not being saved correctly by the server.

Scott Ferguson

unread,
Dec 15, 2013, 7:23:28 PM12/15/13
to app-inventor-de...@googlegroups.com
Are you sure that you have write access to the destination folder?
---
Scott

Kelson Fox

unread,
Mar 1, 2014, 8:48:47 AM3/1/14
to app-inventor-de...@googlegroups.com
Hi Scott

Hope you can help me...
Every time I click to post file, I get "error 1104", then if I click second time the file is sent.

How to get rid of this?


Scott Ferguson

unread,
Mar 2, 2014, 8:32:53 PM3/2/14
to app-inventor-de...@googlegroups.com
I don't know any more than Taifun and Hossein.
---
Scott

kenma...@gmail.com

unread,
Apr 21, 2014, 7:48:26 AM4/21/14
to app-inventor-de...@googlegroups.com
Hi,

We run a coding session for kids here in Ireland.

We are doing an app inventor session to upload images (to a database so the kids can share them). As step one we want to post an image to the directory. However getting zero file sizes. Installed on a local WAMP server or hosted. So we put the whole problem into two files, one to post a file and one to write to remove any possible problems (we have installed the workaround package and fail). Seems that the data from the actual file is just not coming across. 

As its for teach kids, we hoped you would help us :-).

Regards,
M
Ps. outputs on the webbrowser is:
'fakename.jpg
File transfer failed.'

The directory has 'fakename.jpg' with zero bytes.
dojo-save.php
savepicture.php

Taifun

unread,
Apr 21, 2014, 10:35:24 AM4/21/14
to app-inventor-de...@googlegroups.com
as already suggested in this thread:
1. are you able to set the flag always_populate_raw_post_data = on ?
2. in the php script try to replace php://input by php://stdin
3. probably that workaround can help, too: http://puravidaapps.com/postfile.php 
Taifun

Trying to push the limits of App Inventor! Snippets and Tutorials from Pura Vida Apps by Taifun.         

Zoran Kukulj

unread,
Apr 21, 2014, 11:29:25 AM4/21/14
to app-inventor-de...@googlegroups.com
Hi,
Are YOU sure That's the folder ,where picture shouuld ne uploaded, in WAMP (on server) is writable?
--
(you have received this message from the App Inventor Developers Library)
---
You received this message because you are subscribed to the Google Groups "App Inventor Developers Library" group.
To unsubscribe from this group and stop receiving emails from it, send an email to app-inventor-develope...@googlegroups.com.
For more options, visit https://groups.google.com/d/optout.

kenma...@gmail.com

unread,
Apr 21, 2014, 12:46:53 PM4/21/14
to app-inventor-de...@googlegroups.com
Thank you for the quick reply.

Adding the following line works.

file_put_contents("test.txt","can I write");

This works.

In other words the $data variable seems to be empty.

I have tried the stdin and the input.

Hosting is on 000webhost.com

I cannot change the setting  for the on/off item mention above as we need to use a free hosting server (its a volunteer based training, no charge).

Do the files we attached work for you? Could you recommend an alternative hosting site?

Taifun

unread,
Apr 21, 2014, 1:47:04 PM4/21/14
to app-inventor-de...@googlegroups.com
000webhost.com works fine together with my workaround http://puravidaapps.com/postfile.php 
Taifun

Zoran Kukulj

unread,
Apr 21, 2014, 1:48:01 PM4/21/14
to app-inventor-de...@googlegroups.com
Hi,
000webhost.com worked for me as well, so most likely it is not anything related to hosting free.





--

no name

unread,
May 1, 2014, 7:43:51 AM5/1/14
to app-inventor-de...@googlegroups.com
Where do I put the .php file?

Taifun

unread,
May 1, 2014, 9:40:04 AM5/1/14
to app-inventor-de...@googlegroups.com
Where do I put the .php file?
in a directory onto your web server, which is accessible from the internet
Taifun

no name

unread,
May 1, 2014, 4:56:06 PM5/1/14
to app-inventor-de...@googlegroups.com
Where do I put the .php file?
in a directory onto your web server, which is accessible from the internet
Taifun
 Could this work if I'm using Google app engine?

Scott Ferguson

unread,
May 1, 2014, 11:38:01 PM5/1/14
to app-inventor-de...@googlegroups.com
Sorry, I don't know the answer to that.
---
Scott
Message has been deleted

Frederick Borcherds

unread,
Sep 22, 2014, 5:27:10 AM9/22/14
to
Hi. Maybe someone can help me. I have been searching thought many documentation without any success. When I post the file to my server in APP Inventor 2 I get a 200 response code back meaning all went well. The responsecontent however give me the whole html coding of the index.php page and the file did not copy to the relevant folder.

I have tried input and stdin without any success. Anybody knows how to fix this?.

PS: Im running phpfox on the webserver

Regards

Scott Ferguson

unread,
Oct 7, 2014, 3:32:50 PM10/7/14
to app-inventor-de...@googlegroups.com
Try puravidaapps.com for examples of posting data.
---
sf

Edwin Boves

unread,
Dec 27, 2014, 10:53:53 PM12/27/14
to app-inventor-de...@googlegroups.com

Hi, I use 000webhost as well. I have tried Taifuns work around uploading PEAR and WideImage(see image) to my server and I still get an error uploading. Do I have to do anything to my server? Please Help.

To unsubscribe from this group and stop receiving emails from it, send an email to app-inventor-developers-library+unsubscribe@googlegroups.com.

Taifun

unread,
Dec 28, 2014, 9:02:02 AM12/28/14
to app-inventor-de...@googlegroups.com

Sebastián Meza

unread,
Jan 16, 2015, 2:30:58 PM1/16/15
to app-inventor-de...@googlegroups.com
I have the same problem dude...did you finally solve this??

Taifun

unread,
Jan 16, 2015, 4:01:53 PM1/16/15
to app-inventor-de...@googlegroups.com
a lot of people solved this, but without knowing more details of your problem we unfortunately can't help
have you seen this https://puravidaapps.com/postfile.php#q
Taifun

Sebastián Meza

unread,
Jan 16, 2015, 4:38:03 PM1/16/15
to
Finally i can send the images to the server. Only need to know how to obtain the url of the image in the php code to save it in my database.

Finalmente puedo enviar imágenes al servidor. Sólo necesito saber como obtener la url de la imagen recién subida en el código php para guardar esta dirección eb mi base de datos.


Cheers!!

Taifun

unread,
Jan 16, 2015, 4:47:32 PM1/16/15
to app-inventor-de...@googlegroups.com
this depends on the php script
if you use my solution, you will find the images in the same directory as you stored the php script...
Taifun

Sebastián Meza

unread,
Jan 16, 2015, 4:49:41 PM1/16/15
to app-inventor-de...@googlegroups.com
Ok...thanks for your help dude!

--
(you have received this message from the App Inventor Developers Library)
---
You received this message because you are subscribed to a topic in the Google Groups "App Inventor Developers Library" group.
To unsubscribe from this topic, visit https://groups.google.com/d/topic/app-inventor-developers-library/Sc4a1wZHL-Q/unsubscribe.
To unsubscribe from this group and all its topics, send an email to app-inventor-develope...@googlegroups.com.

Brown Bear

unread,
Jan 30, 2015, 5:11:05 AM1/30/15
to
@taifun: Btw I have an error while trying with your method in http://puravidaapps.com/postfile.php. (I am still very newbie here) May you help me? I am using www.000webhost.com
Firstly, I have followed your steps

Install the PEAR package

    1. Download the PEAR::PHP_Compat package, I used the file PHP_Compat-1.6.0a3.tgz, which will be stored on your computer
    2. Unzip the package (you can use any unzip program, for example 7 zip), a directory PHP_Compat-1.6.0a3 will be created containing another zipped file PHP_Compat-1.6.0a3.tar
    3. Unzip that file and another PHP_Compat-1.6.0a3 directory and a file package.xml will be created
    4. Copy that inner directory PHP_Compat-1.6.0a3 to your server into the same directory of the postfile.php script. This directory contains the 2 subdirectories Compat and tests and a file package-test.php
I have attached three images for you.

Thank you Taifun.

Really appreciate your help.

the-error.png
code.png
ftp.png

Brown Bear

unread,
Jan 30, 2015, 7:00:47 AM1/30/15
to
Hi all,

I got the answer already. hahahaha thank you all :D.
The answer: I put the folder not properly. I have attached an image for the right one.

@Taifun: How to post an image into http://www.example.com/php/example-page.html using script? Let say, the "example-page.html" is already made in the directory (server).

Thank you

 
correct-new.png

Taifun

unread,
Jan 30, 2015, 9:41:55 AM1/30/15
to app-inventor-de...@googlegroups.com
How to post an image into http://www.example.com/php/example-page.html using script? 
your question does not make any sense. A html file is a html file and not a directory. You can post an image only into a directory (and not into a html file)
Taifun

Brown Bear

unread,
Jan 31, 2015, 8:16:47 AM1/31/15
to app-inventor-de...@googlegroups.com
@Taifun: okay, sorry for that. Let me try again hahaha

And btw, Thank you for your post in http://puravidaapps.com/postfile.php for resizing an image. It works very well. Thank you so much. :) 
Message has been deleted

farchid honarmand

unread,
Mar 10, 2015, 7:55:39 PM3/10/15
to app-inventor-de...@googlegroups.com
Hi Jon, did you find a solution for this issue ? Thanks

Le lundi 16 décembre 2013 00:37:20 UTC+1, Jon Reneberg a écrit :


On Sunday, December 15, 2013 6:02:27 PM UTC-5, Taifun wrote:
I am also getting the full file name saved with 0kb.  Is this a permission issue?  
in the php script try to replace php://input by php://stdin

Hmmm...  Still get the file with 0kb.
When I press the "Post" button, it takes 90 seconds or so before I get the "File xfer completed." message which leads me to believe that the Android app is uploading the full image, but it's somehow not being saved correctly by the server.

cd tech

unread,
Jul 5, 2015, 1:29:12 PM7/5/15
to app-inventor-de...@googlegroups.com
Hi, i use typhoon script to transfert file to my server.
Everything is ok exept the file created is empty 
After readind this post, i change php://input with php://stdin,  but now the file is not tranfered .

Any idea please??

Rudi van Heerden

unread,
Nov 3, 2015, 2:31:28 AM11/3/15
to App Inventor Developers Library
Hi Scott

I get a warning that say: "Warning: file_put_contents(): Filename cannot be empty in ........"

What can be the problem?

Rudi

Scott Ferguson

unread,
Nov 3, 2015, 7:28:09 AM11/3/15
to App Inventor Developers Library
I would need to see a screen shot of your blocks.
It looks like a message from the php server that would indicate that your file name string sent from App Inventor is empty?
---
sf

Husain

unread,
Nov 18, 2015, 8:39:24 AM11/18/15
to App Inventor Developers Library
That's great. How do I change the directory of uploaded files instead of the main directory?

Scott Ferguson

unread,
Nov 18, 2015, 8:57:26 AM11/18/15
to App Inventor Developers Library
I am very rusty on php, but I think it can create a directory on-the-fly if you include the directory name in the path where you intend to store the data.
So instead of 'myfile.dat' you might try 'newfolder/myfile.dat'.
And the new folder would be created in your user directory?
---
sf

Husain

unread,
Nov 27, 2015, 5:09:51 PM11/27/15
to App Inventor Developers Library
Still didn't get it working

here is my code:

  require_once (dirname(__FILE__).'/Compat/Function/file_get_contents.php');
  $data
= php_compat_file_get_contents('php://input');
 
  $filename
= $_GET['filename'];
 
if (file_put_contents($filename,$data)) {
   
if (filesize($filename) != 0) {
             
// Do whatever if file uploaded

Scott Ferguson

unread,
Nov 27, 2015, 9:29:06 PM11/27/15
to App Inventor Developers Library
So does the subdirectory get created, but is empty?
Is the file created, but is empty?
What are you passing for 'filename'?
Does it contain the subdirectory name?
---
sf

Tim Carter

unread,
Mar 8, 2016, 6:10:07 PM3/8/16
to App Inventor Developers Library


Scott's original example with the change from input to stdin and php.ini file (to change always_populate_raw_post_data = on) working fine here on an open ftp. Many thanks

What changes are needed to the blocks to upload a file to a user/pass protected web server?

Tim

Scott Ferguson

unread,
Mar 8, 2016, 9:03:45 PM3/8/16
to App Inventor Developers Library

Tim Carter

unread,
Mar 9, 2016, 12:56:18 PM3/9/16
to App Inventor Developers Library
Yes it did !  :)

I had used this before to download but forgotten about it. :(

Thank you Taifun :)

For others:

Encode your username and password to Base 64: http://ostermiller.org/calc/encode.html
using the format: user:password

Add the following blocks before Web1,URL block, and paste your encoded login info after the word Basic in the text block


That's it, should just work.


Thanks guys


Tim

Scott Ferguson

unread,
Mar 9, 2016, 6:33:07 PM3/9/16
to App Inventor Developers Library
Thanks for letting us know how you solved it :-)
---

Gabriele Cozzolino

unread,
Jun 4, 2016, 3:12:15 AM6/4/16
to App Inventor Developers Library
Thank you all for your precious examples, it's working fine but I have one major issue: I can't display back the image saved on the website if it is a high resolution photo (1-2mb file). I mean, it's correctly saved on the cloud, but the image component doesn't shows it, I think for some Android restriction. There's a solution for this? There's a way to resize the image or shrink its size? Thanks

Scott Ferguson

unread,
Jun 4, 2016, 7:48:30 AM6/4/16
to App Inventor Developers Library
Maybe look at:

For images to store in an app, you can either use some utility app to resize an image on the computer (ie. windows paint) and/or you can compress the image using a utility such as the service tinypng.com
---

Taifun

unread,
Jun 4, 2016, 8:45:52 AM6/4/16
to App Inventor Developers Library
There's a way to resize the image or shrink its size?
my Image Extension can do it...

The App Inventor Extensions are currently in testing. See the announcement for more information and read the App Inventor Extensions document about how to use an App Inventor Extension.

Taifun

Trying to push the limits of App Inventor! Snippets, Tutorials and Extensions from Pura Vida Apps by Taifun. 

Gabriele Cozzolino

unread,
Jun 4, 2016, 9:49:59 AM6/4/16
to App Inventor Developers Library
Actually I meant to resize it on the fly before uploading with php.
Taifun I'd love to use your extension, but I'm using Appy builder that sadly doesn't supports extensions yet. Maybe sometime in the near future I hope...
Then, I'm really not good with php, so I doesn't know how to modify the current script to also resize the image, thanks anyway.

Taifun

unread,
Jun 4, 2016, 12:59:18 PM6/4/16
to App Inventor Developers Library
on the server side you might want to take a look into the Wide Image library for php

Gabriele Cozzolino

unread,
Jun 4, 2016, 4:46:07 PM6/4/16
to App Inventor Developers Library
Thank you for point me to the right way, I've done what I need (I'll share the modified script later on), but I have one major issue with the original script: the image file saved on the server is corrupted (grey or red area at the bottom of the photo). On what could this depend? Thanks

Gabriele Cozzolino

unread,
Jun 4, 2016, 4:46:50 PM6/4/16
to App Inventor Developers Library
ps. Original image is not corrupted, also I tried with different ones

Gabriele Cozzolino

unread,
Jun 4, 2016, 5:01:14 PM6/4/16
to App Inventor Developers Library
Sorry for multiple posting, ignore my latest messages, actually it WAS a problem with some of my photos.
Here it is my modified script (WideImage required: http://wideimage.sourceforge.net/), hope it helps somebody else:

if($_GET['p']==$ACCESSKEY){
 
// this is the workaround for file_get_contents(...)
  require_once
(dirname(__FILE__).'/PHP_Compat-1.6.0a3/Compat/Function/file_get_contents.php');
  require_once
(dirname(__FILE__).'/wideimage/WideImage.php');

  $data
= php_compat_file_get_contents('php://input');


  $filename
= $_GET['filename'];

  $resfilename
= $_GET['resfilename'];
 
if (file_put_contents($filename,$data)) {
 
WideImage::load($filename)->resize('50%')->saveToFile($resfilename);
   
if (filesize($filename) != 0 && filesize($resfilename) != 0)  {
      echo
"File transfer completed.";
   
} else {
      header
("HTTP/1.0 400 Bad Request");
      echo
"File is empty.";
   
}
 
} else {
    header
("HTTP/1.0 400 Bad Request");
    echo
"File transfer failed.";
 
}
} else {
  header
("HTTP/1.0 400 Bad Request");
  echo
"Access denied";     //reports if accesskey is wrong
}

Message has been deleted

Gabriele Cozzolino

unread,
Jun 4, 2016, 5:19:50 PM6/4/16
to app-inventor-de...@googlegroups.com
Consider that I'm still using original method to upload photos, I used WideImage library in combination to save a second resized copy of the file. So, also original method fails. 
But as I said I think it depends of some of my photos: somehow some of that results corrupted after the upload, but others are fine. It's not a random issue, this is happening repeatedly with same photos.

2016-06-04 23:02 GMT+02:00 Taifun <taifu...@gmail.com>:
can you upload the image successfully without using that library?
Taifun

--
(you have received this message from the App Inventor Developers Library)
---
You received this message because you are subscribed to a topic in the Google Groups "App Inventor Developers Library" group.
To unsubscribe from this topic, visit https://groups.google.com/d/topic/app-inventor-developers-library/Sc4a1wZHL-Q/unsubscribe.
To unsubscribe from this group and all its topics, send an email to app-inventor-develope...@googlegroups.com.
For more options, visit https://groups.google.com/d/optout.

Reply all
Reply to author
Forward
0 new messages