Send xmlhttprequest to external server

25 views
Skip to first unread message

Jordan

unread,
Oct 14, 2009, 3:55:12 AM10/14/09
to Gears Users
I am using Google Gears and Desktop to select multiple images.
I reduce the size with canvas, and upload to our company web server.
(to save time, I reduce and upload instead of upload and reduce and is
working fine)

Now I have to store the thumbnailed image and the full size images at
the central server.
To don't lose the saved upload time, as I have multiple offices with a
local server for each office,
I thought to send the thumbnail to the web server, and the full size
image to the lan server and syncronize with another software.

But for "security reasons" the xmlhttprequest cant be sent to a
different server that one the javascript runing server.

I am trying to do the next :
MyPC -> PickFiles (only one time)
Send ThumbSize to -> WebServer
Send FullSize to -> LocalServer

Some ideas ??

I tried with a form and an input file type, but I cant set the origin
of the input ("security reasons" again), and I won't select the files
one by one as I don't know the number of images.

Thanks to all.

Jordan

unread,
Oct 17, 2009, 7:25:38 AM10/17/09
to Gears Users
I put the upload pages at the local server, and I will load the page
in an IFRAME, but I dont like this method, beacuse I will need copy
the application software, and to do changes i will need to update all
the servers and check them.

If anybody knows how to do with the external calls, I will be very
happy.

Drew

unread,
Oct 17, 2009, 1:18:37 PM10/17/09
to Gears Users
Same origin policy means that you can't do real XHR to a remote
server, but there are a few workarounds:

1. Use the local server as a proxy. Do an XHR post to the local
server, and then have that server turn around and post the data to the
central server.

2. Use a script tag instead of XHR. This is a good technique for cross-
site javascript when the request data is simple, but since you're
limited to using the query string, it's not a good solution for
sending actual files.

3. Use a hidden form and iframe. Do all your image manipulation
locally, then if you need to send something to a remote server, base64
the blob, attach that to a form and post to an iframe.

Jordan

unread,
Oct 20, 2009, 3:52:35 AM10/20/09
to Gears Users
Thanks for your answer Drew.

Yesterday they give me 128 MB of images.

1) is not useful. If I use the remote server as proxy, I have a low
upload bandwith. I had the remote server as proxy and upload speed was
20-30kb/s.

2) send the files in the URL as a GET info or in url of page loadad ?

3) I dont know how to attach the blob to the form, but I will look for
info.

Eduard Martini

unread,
Oct 20, 2009, 7:30:19 AM10/20/09
to Gears Users
I think that "base64 the blob, attach that to a form" means to encrypt
the blob in base64 and put it as a hidden field (text) to a form.
Then on server decrypt the base64 string and read the blob.

I think this will not work because I don't think there is any JS code
to base64 encrypt binary data (I think all JS base64 encryption
libraries can only encrypt ASCII).

If you try that, please post back the result and maybe what libraries
you used for ecription/decription.

Jordan

unread,
Nov 6, 2009, 3:42:08 AM11/6/09
to Gears Users
I have done the next :

At the remote server I detect the public IP of the client and if it is
at one of our offices, I set the link to load the upload pages from
the local server.

At the local servers I put all the scripts (javascript & php) to
upload the files. I send the full files to the local server, and the
php script makes a thumbnail of the images and send throught post to
the remote server.

My first scenario I tried:
-Select and reduce from client
-Send full images to local server
-Send thumbnails to remote server

My second scenario I tried:
-Select from client
-Send full images to local server
-Send thumbnails from the local server to remote server

The second scenario is about 5-10% more slower (totaly 70-80 seconds
for 30 MB).
With the first scenario the time between the client has to wait the
javacript finish to create thumbnails, that is about 50% of the time.
In the second scenario only few seconds.
In the first scenario, remote and local files are send at the same
time, in the second, untill the local file is sent, the remote file
isn't send.

I finaly chosed for the second because I prefere the user machine
working, and not frozen the thumbnail time.
The second reason is that I insert the filename in a database and
rename the file based on the ID inserted at the table, and with this
method, I send the thumbnail with the ID based name instead of the
original filename.

It prevents remote client to upload outside of our networks, it's
possible I maintain the full upload directly to remote server but it
will be slow.

I will try to upload the scripts

Jordan

unread,
Nov 6, 2009, 3:45:31 AM11/6/09
to Gears Users
Ah, I had to disable the proxy settings, as our proxy is our remote
server, the files send to our local server where sent trought our
remote server doing the upload very very slow.
I supose that if you have a local proxy you wont have these problem.
Reply all
Reply to author
Forward
0 new messages