tags:

views:

49

answers:

6

Folks

I have an image at some server (SOURCE) i.e. http://stagging-school-images.s3.amazonaws.com/2274928daf974332ed4e69fddc7a342e.jpg

Now I want to upload it to somewhere else (DESTINATION) i.e. example.mysite.com/receiveImage.php

First, I am copying image from source to my local server and then uploading it to destination. It's perfectly working but taking too much time as it copy the image and then uploads... I want to make it more simple and optimized by directly uploading image from source URL to destination URL.

Is there a way to handle this ?

I am using php/cURL to handle my current functionality.

Any help would be very much appreciated.

Cheers !!

A: 

One of the services may have a form somewhere that will allow you to specify a URL to receive from/send to, but there is no generic HTTP mechanism for doing so.

Ignacio Vazquez-Abrams
Both services are not controlled by me, I am handling it in the middle. In fact I store user images to s3 service by Amazon and now wanting them to transfer to some other service but without copying them to my local server to eliminate time consumption.
Amjad Shaick
Then the best you can do is stream it by reading (say) 4kB at a time before writing it back out.
Ignacio Vazquez-Abrams
A: 

The only way to transfer the image directly from source to destination is to initiate the transfer from either the source or the destination. You can't magically beam the data between these two locations without them talking to each other directly. If you can SSH login to your mysite.com server you could download the image directly from there. You could also write a script that runs on mysite.com and directly downloads the image from the source.

If that's not possible, the best alternative may be to play around with fread/fwrite instead of curl. This should allow you to read a little bit from the source, then directly upload that bit to the destination so download and upload can work in parallel. For huge files this should make a real difference, for small files on a decent connection it probably won't.

deceze
OOPS !! Problem is, I am in the middle of these two sites :-s
Amjad Shaick
@Amjad Well, then the only thing you can do is optimize the down/upload, but you'll *have* to download and upload the file if the two services won't talk to each other directly.
deceze
+1  A: 

If example.mysite.com/receiveImage.php is your own service, then you may

  1. pass SOURCE URL to your PHP script as GET or POST parameter
  2. in PHP script, use file_get_contents() function to obtain image by URL, and save it to your storage

Otherwise it's impossible by means of HTTP.

However, there are some ways to increase files uploading speed a little:

  • If files are huge, you may use two threads: one for downloading (it will store all downloaded data to some buffer) and one for uploading (it will get all available data from buffer and upload it to site). As far as I know, this can't be done easily with PHP, because multi-threading is currently not supported yet.

  • If there are too many files, you may use many threads / processes, which will do download/upload simultaneously.

By the way, these means do not eliminate double traffic for your intermediate service.

Kel
No, its not my service. So I can't handle it on that side. I am simply copying files first on my local server and then uploading... which taking too much time so I want to skip copying time.
Amjad Shaick
Then, I suppose, it's impossible in HTTP :(
Kel
I've updated answer with a couple of thoughts - probably it would be useful.
Kel
A: 

create two textfield one url, other filename in php, use : uploadDir is path to your file directory ;)

 copy($url, $uploadDir.'/'.$fileName);
nerkn
I am already doing this, I just want to skip copy thing..
Amjad Shaick
A: 

copy($url, $uploadDir.'/'.$fileName);

nerknn
A: 

I just released this: http://github.com/mjhm/cURLServer. It may be exactly what you need. You'll need to launch an AWS instance to use it, but it will definitely give you a faster path to your destination.

mjhm