Coder Social home page Coder Social logo

Comments (12)

lildude avatar lildude commented on July 18, 2024

It appears the host your running this code on can't actually communicate with the SmugMug API endpoint (api.smugmug.com).

Are you able to run any of the examples provided with phpSmug on this server without any errors?
If not, is this server behind a firewall or proxy?

If the examples provided with phpSmug work on this host, can you please paste the exact code you are using to perform the uploads. Please remove your API keys and passwords from the code you paste.

from phpsmug.

Aneetha avatar Aneetha commented on July 18, 2024

hi,

I have attached the source which i am using to upload the images. Please have a look on it.

<?php 
set_time_limit(0);
require_once("phpSmug/phpSmug.php");

//Gets the server details.
$CmnAPIKey = "fdvfdv2vKNH546546546h";
$CmnSecret = "gfdgfdgdec677a654654654";

    $f=new phpSmug("APIKey=$CmnAPIKey", "AppName=Appname/1.0 (http://www.domain.com/Test-smugmug-api-upload.php)","OAuthSecret=$CmnSecret","");

    $TokenKey="54645645b20654654";
    $Secret="hnnd40455fd2ccbvnvbnvbnbv";

    $f->setToken("id={$TokenKey}", "Secret={$Secret}");                                  
    $strImgs="http://www.domain.com/smugmug-photos/39251-29261-Ward,David/Slides/Box1/39251-Box1-021.jpg~http://www.domain.com/smugmug-photos/39251-29261-Ward,David/Slides/Box1/39251-Box1-022.jpg~http://www.domain.com/smugmug-photos/39251-29261-Ward,David/Slides/Box1/39251-Box1-023.jpg~http://www.domain.com/smugmug-photos/39251-29261-Ward,David/Slides/Box1/39251-Box1-024.jpg~http://www.domain.com/smugmug-photos/39251-29261-Ward,David/Slides/Box1/39251-Box1-025.jpg~http://www.domain.com/smugmug-photos/39251-29261-Ward,David/Slides/Box1/39251-Box1-026.jpg~http://www.domain.com/smugmug-photos/39251-29261-Ward,David/Slides/Box1/39251-Box1-027.jpg~http://www.domain.com/smugmug-photos/39251-29261-Ward,David/Slides/Box1/39251-Box1-028.jpg~http://www.domain.com/smugmug-photos/39251-29261-Ward,David/Slides/Box1/39251-Box1-029.jpg~http://www.domain.com/smugmug-photos/39251-29261-Ward,David/Slides/Box1/39251-Box1-030.jpg~http://www.domain.com/smugmug-photos/39251-29261-Ward,David/Slides/Box1/39251-Box1-031.jpg~http://www.domain.com/smugmug-photos/39251-29261-Ward,David/Slides/Box1/39251-Box1-032.jpg~http://www.domain.com/smugmug-photos/39251-29261-Ward,David/Slides/Box1/39251-Box1-033.jpg~http://www.domain.com/smugmug-photos/39251-29261-Ward,David/Slides/Box1/39251-Box1-034.jpg~http://www.domain.com/smugmug-photos/39251-29261-Ward,David/Slides/Box1/39251-Box1-035.jpg~http://www.domain.com/smugmug-photos/39251-29261-Ward,David/Slides/Box1/39251-Box1-036.jpg~http://www.domain.com/smugmug-photos/39251-29261-Ward,David/Slides/Box1/39251-Box1-037.jpg~http://www.domain.com/smugmug-photos/39251-29261-Ward,David/Slides/Box1/39251-Box1-038.jpg~http://www.domain.com/smugmug-photos/39251-29261-Ward,David/Slides/Box1/39251-Box1-001.jpg~http://www.domain.com/smugmug-photos/39251-29261-Ward,David/Slides/Box1/39251-Box1-002.jpg~http://www.domain.com/smugmug-photos/39251-29261-Ward,David/Slides/Box1/39251-Box1-003.jpg~http://www.domain.com/smugmug-photos/39251-29261-Ward,David/Slides/Box1/39251-Box1-004.jpg~http://www.domain.com/smugmug-photos/39251-29261-Ward,David/Slides/Box1/39251-Box1-005.jpg~http://www.domain.com/smugmug-photos/39251-29261-Ward,David/Slides/Box1/39251-Box1-006.jpg~http://www.domain.com/smugmug-photos/39251-29261-Ward,David/Slides/Box1/39251-Box1-007.jpg~http://www.domain.com/smugmug-photos/39251-29261-Ward,David/Slides/Box1/39251-Box1-008.jpg~http://www.domain.com/smugmug-photos/39251-29261-Ward,David/Slides/Box1/39251-Box1-009.jpg~http://www.domain.com/smugmug-photos/39251-29261-Ward,David/Slides/Box1/39251-Box1-010.jpg~http://www.domain.com/smugmug-photos/39251-29261-Ward,David/Slides/Box1/39251-Box1-011.jpg~http://www.domain.com/smugmug-photos/39251-29261-Ward,David/Slides/Box1/39251-Box1-012.jpg~http://www.domain.com/smugmug-photos/39251-29261-Ward,David/Slides/Box1/39251-Box1-013.jpg~http://www.domain.com/smugmug-photos/39251-29261-Ward,David/Slides/Box1/39251-Box1-014.jpg~http://www.domain.com/smugmug-photos/39251-29261-Ward,David/Slides/Box1/39251-Box1-015.jpg~http://www.domain.com/smugmug-photos/39251-29261-Ward,David/Slides/Box1/39251-Box1-016.jpg~http://www.domain.com/smugmug-photos/39251-29261-Ward,David/Slides/Box1/39251-Box1-017.jpg~http://www.domain.com/smugmug-photos/39251-29261-Ward,David/Slides/Box1/39251-Box1-018.jpg~http://www.domain.com/smugmug-photos/39251-29261-Ward,David/Slides/Box1/39251-Box1-019.jpg~http://www.domain.com/smugmug-photos/39251-29261-Ward,David/Slides/Box1/39251-Box1-020.jpg";

    $lmt=$_GET["lmt"];

    $arr=explode("~",$strImgs);
    if(count($arr)>$lmt)
    {
        //foreach($arr as $OriginalImgPath)
        //{
            $OriginalImgPath=$arr[$lmt];
            $path_parts = pathinfo($OriginalImgPath);
            $OriginalFileName=$path_parts["basename"];
            $Caption=$path_parts["filename"];
            $ImageUploadFromURL=$f->images_uploadFromURL("AlbumID=654645645","URL=$OriginalImgPath","FileName=$OriginalFileName","Caption=$Caption","Heavy=1");
        //}

        $lmt = $lmt+1;
        echo "<meta http-equiv=\"refresh\" content=\"2;url=http://www.domain.com/Test-smugmug-api-upload.php?lmt=$lmt\">";
    }
    else
    {    
     echo "Success";
    }
?>

from phpsmug.

Aneetha avatar Aneetha commented on July 18, 2024

Also, the upload is working for 10 images or 5 images, then it thrown the error message (post #1).

If the server is behind the firewall/proxy mean, what should be the solution for this ?

Consider this message as well: Unable to connect to api.smugmug.com (Error Code: 0)

from phpsmug.

lildude avatar lildude commented on July 18, 2024

The error message "Unable to connect to api.smugmug.com (Error Code: 0)" means this server couldn't communicate with that URL. This is why I stated...

It appears the host your running this code on can't actually communicate with the SmugMug API endpoint (api.smugmug.com).

...and asked if you were behind a proxy or firewall.

As you can upload some images, I don't think this is an issue with your communication unless you have an anonymous proxy or firewall that is throttling your connections or blocking your access after a certain amount of data has passed through. You'll need to check with your network admins to see if this is the case.

I'll do some testing to see if I can reproduce this issue (I'm not behind a firewall or proxy which limits me in anyway).

In the mean time, could you make sure your PHP has Curl support compiled in and enabled (you may need to just enable the extension) and try using Curl to upload by adding the following line just after your $f=new phpSmug("APIKey... line:

$f->setAdapter('curl');

Note, this will only work if you actually have curl support in your php instance.

from phpsmug.

Aneetha avatar Aneetha commented on July 18, 2024

The curl is enabled along with PHP installation. Also i have tried by adding $f->setAdapter('curl'); in our script.

But got the same error after a particular images get uploaded into Smugmug. I will check with my server admin regarding the proxy settings and will let you know.

from phpsmug.

lildude avatar lildude commented on July 18, 2024

I've done some testing and your code (with a few modifications specific to my env and my API access) works perfectly for me using both socket and curl adapters.

I definitely think this is something on your network blocking your access.

from phpsmug.

Aneetha avatar Aneetha commented on July 18, 2024

Please check this continuously with 50 of 200 images (that is 4 times with 50 images), the image size should be more than 3 MB. Because i got the error after 3rd or 4th cycle, sometimes in first cycle. In the mean-while, I will check with my server admin regarding the proxy settings and will post his comments.

from phpsmug.

lildude avatar lildude commented on July 18, 2024

The image size shouldn't matter from phpSmug's perspective as it isn't actually doing the uploading. Smugmug is doing the uploading itself by pulling the image directly from the URL you specify.

That said, as Smugmug is doing the pulling, why not just do a foreach() on your array without the page refresh and leave it to Smugmug to do the rest?

from phpsmug.

lildude avatar lildude commented on July 18, 2024

Ok, I've reproduced the issue. It appears sometimes api.smugmug.com is a little slow to respond and it doesn't send any data within the 30 seconds phpSmug allows it to respond.

At the moment, there isn't an easy way to increase this time out without modifying the source, but there are two solutions I've found:

  1. Do as per my previous note and use a foreach() loop to loop through the array of URLs without the refresh and allow SmugMug to pull the images in it's own time. You may need to increase the maximum execution time for php scripts on your server to allow this, or break up the list of image urls into smaller chunks. This may not necessarily resolve the issue though as the API could still be slow for one of your requests.
  2. Modify phpSmug.php and add 'timeout' => 60 to the $this->req->setConfig() in the __construct() method as follows (I've added it to the end of the line):
$this->req->setConfig( array( 'adapter' => $this->adapter, 'follow_redirects' => TRUE, 'max_redirects' => 3, 'ssl_verify_peer' => FALSE, 'ssl_verify_host' => FALSE, 'connect_timeout' => 60, 'timeout' => 60 ) );

If this last one works for you, I'll need to create a method to make setting this easier, or possibly just increase the default to 60 seconds.

from phpsmug.

Aneetha avatar Aneetha commented on July 18, 2024

1)We have tried using foreach with out setting any timeout parameter and meta refresh, but we got an error.

2)After setting the timeout as you have mentioned in the point #2, it worked.

3)We are uploading more than 5000+ images(eac contains size aprox 8 to 10 MB) to SmugMug by creating new galleries, albums, sub albums and also doing some db update for our records, While doing all these things, the PHP script will get timed out. This is the reason why we go for meta refresh.

As of now the your point #2 is working for us, we have set "timeout=>120", please let us know is this a stable solution or is there any other better way to avoid this issue?

from phpsmug.

lildude avatar lildude commented on July 18, 2024

Good to hear you've got a working solution. That IS a stable solution. The default setting is 30 seconds. You're just increasing this to 120 which should give the SmugMug API plenty of time to respond.

I'll add a helper function to a future release of phpSmug which will allow you to increase this timeout without having to modify the source.

from phpsmug.

Aneetha avatar Aneetha commented on July 18, 2024

Okay, thanks for the solution

from phpsmug.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.