Thanks Guy!

4 views
Skip to first unread message

Alyxandor

unread,
Jun 25, 2009, 4:01:23 AM6/25/09
to GoogleFileService
Hey man, nice little library.
The 1GB max file limit some people whine about is only the free quota,
enough for test. Deploying any app that will let users upload many
large files will cost you money, either in external hosting, or $0.15/
GB on GAE, so no biggy...

I'm going to add to your code, and make some sort of image-smasher,
which will do something like:
domain.com/img?x=150x150&y=imgName to auto-resize images, cache the
response in server and client, and output image blobs to users.
{Then, eventually integrate it with gwt sprites to make a stand-alone
scalable-sprite API...}

You just saved me lots of time getting an image upload backend
working... In php, it took me eight hours, in gae... twenty
minutes. I know there's a 1MB limit on Image API calls, so I'm
considering a secondary option... If image uploads are over 1M, throw
error and {using gwt} tell user, "File Size Too Large, Please Retry
Using Our Private Image Server", and print a new upload form pointing
to said php code on my unlimited-space server.

I was thinking,
"user clicks upload" ->
-> Print, "Uploading to Image Server...", whilst uploading.
Php gets image, scales down to 1M, prints, "Resizing and Saving Image"-
>
-> Javascript sets window.location to externalUpload.jsp, which
tells GAE what url to access a 1M resized image on external server,
UrlFetch said image, toss in BigTable, scale to size and print to
screen as needed.

When I get it done, would you like me to merge code with your project,
or would you rather I extract the uploads / imaging bits into a new
project?

Hyllier Leunam

unread,
Jun 25, 2009, 4:26:18 AM6/25/09
to google-fi...@googlegroups.com
Hi, Alyxandor, what you just said is what I need... I need to store
the files into my own server but using an app engine web interface for
the upload form, I think that this can be done with some java code...
But I need help, please teach me how to solve my problem... my mail is
hyl...@gmail.com

2009/6/25, Alyxandor <a.revolutio...@gmail.com>:

Alyxandor

unread,
Jun 25, 2009, 10:22:15 AM6/25/09
to GoogleFileService
There are two ways to do this. The idea I posted for GoogleFileUpload
was very generic, and actually kind of wrong.

If you just want to post forms in GAE that upload to a different
server, use:


<form name="upForm" action="not.gae/uploadScript.php?x=..."
target="noreload" enctype="multipart/form-data" method="post">
<input type="file" size="30" name="upload"></input>
<input name="Submit" onclick="return upload();" value="upload"
type="submit"></input>
</form>

This is a form that targets a different server, and posts all the
inputs, including the file field, to your upload script. You could
make this upload script a servlet, and basically copy+paste the
GoogleFiles implementation, but ditch all the appengine stuff and just
use regular java.io.File routines in the servlet...

...But java hosting costs money, and php is cheaper and often better
hosting {except GAE, which is FREE and Java and on the Google Cloud}.
So, here's a quick rundown of what your php has to do:

<?php
$upload = $_FILES['upload']; //The text 'upload' is the name of the
file input in the form
$uploadfile= $upload['tmp_name'];//This is a temporary file from the
upload, in /tmp
$uploadname=$upload['name'];//The user's original name. You don't
NEED this

$srcfile = fopen($uploadname,'r');//Open the temp file for reading
$data = fread($srcfile,filesize($uploadname));//Put data into memory
fclose($srcfile);//Close the file

//Next, open a file stream for output, make sure it's in your server's
web folder
$dstfile = fopen('/home/your/account/dir/public_html/'.
$uploadname,'w');//Get OR make
fwrite($dstfile,$data);//Put data in file
fclose($dstfile);//Close file

echo 'File upload successful!';
?>

When done, this will put an upload 'sweetPic.jpg' into 'http://
your.site/sweetPic.jpg'...

Just beware, php sometimes limits file upload size.



Should you decide to access this data later in GAE, you can use
URLFetch to get it off your server.


For some real trickery, instead of echo 'File upload successful', try:

echo '<html><head/><body><script>window.location='your-gae-
site.appspot.com/postUploadServlet?name=$uploadname';</script>';

This will redirect back to GAE, where you can display your external
files, like images with <img src="other.site/sweetPic.jpg" />, or
<iframe src="other.site/fileName.ext" />... The filename used should
be sent back to GAE using a parameter so the php can tell it what
filename it used to save with.


There's a LOT of details and overhead you SHOULD deal with to
implement something like this {like restricting uploads to requests
that are referred from you GAE site}, but I think this should be
enough to help you along.


PS - Basic Imagery widget w/ scaling, cropping and fading is almost
done... I might make a google code project from it, provided I get the
blessing of T Y Tung... And maybe with a little gwt flavour as
well...


On Jun 25, 2:26 am, Hyllier Leunam <hyll...@gmail.com> wrote:
> Hi, Alyxandor, what you just said is what I need... I need to store
> the files into my own server but using an app engine web interface for
> the upload form, I think that this can be done with some java code...
> But I need help, please teach me how to solve my problem... my mail is
> hyll...@gmail.com
>
> 2009/6/25, Alyxandor <a.revolution.ultra.b...@gmail.com>:

Alyxandor

unread,
Jun 25, 2009, 10:32:35 AM6/25/09
to GoogleFileService
Ooops... Copy+Paste = sloppy...



<form name="upForm" action="not.gae/uploadScript.php?x=..."
target="_self" enctype="multipart/form-data" method="post">
<input type="file" size="30" name="upload"></input>
<input name="Submit" value="upload" type="submit"></input>
</form>


This is the form. Put it in it's own .html so you can serve it up in
an iframe, otherwise it will reload the whole page when it's done.
You can change target="targetName" to a different frame to have it
reload instead, {for example, an iframe with name="targetName"
id="targetName"}.

This file is on GAE if you use hidden iframe targets, or on either
server if you are putting the whole form in it's own iframe.

The php must not be on GAE, as that's just silly.

If there are any more questions, lemme know. When I finish with my
image uploador / editor, it will have the ability to call an external
php script, serve up and images > 1MB from BigTable TO the external
server {by telling external php how to ask gae for the image}, have
php scale the image down to 1M, return it {directly in body of the
instruction GET} to the gae server, let gae use Image transforms on
the image, save to server and send to client. Thus, users can upload
huge images without saying, "Sorry, please learn how to scale your
images down to 1M"... And ANYONE anywhere can get file uploads and
image tools for free, at high speeds, in under an hour...

tytung

unread,
Jun 27, 2009, 4:20:15 AM6/27/09
to GoogleFileService
Hi, Alyxandor

Thanks for your interest.
I'm so glad that my code is useful for you.

I can add you as a 'project member' in http://code.google.com/p/google-file-service/
Then you can add a new branch project such as
http://code.google.com/p/google-file-service/source/browse/branches/GoogleImageFileService
or any name you want.
If you accept the above mode, I will add your gmail account as a
'project member' soon.

Best,
tytung

On 6月25日, 下午4時01分, Alyxandor <a.revolution.ultra.b...@gmail.com>
wrote:

tytung

unread,
Jun 28, 2009, 5:20:35 AM6/28/09
to GoogleFileService
Hi, Alyxandor

I think adding a new google code project should be more convenient for
you.
You can have more control ability on your new google code project.
And please put a URL points to my project website on your new project
website if possible.
Thank you.

tytung

On 6月27日, 下午4時20分, tytung <tyt...@gmail.com> wrote:
> Hi, Alyxandor
>
> Thanks for your interest.
> I'm so glad that my code is useful for you.
>
> I can add you as a 'project member' inhttp://code.google.com/p/google-file-service/
> Then you can add a new branch project such ashttp://code.google.com/p/google-file-service/source/browse/branches/G...
> > project?- 隱藏被引用文字 -
>
> - 顯示被引用文字 -
Reply all
Reply to author
Forward
0 new messages