Get image URL on upload

Comments

7 comments

  • Avatar
    felix kalu

    Hi i am having very similar issue. i am trying to save the url of the input files on my database after they are uploaded to cloudinary but i can't find anyway to retrieve the url string of the uploaded files.

    The cloudinary.v2.uploader.upload(" ", { }, function(error, result) ) method returns a result after the files are uploaded and i am able to access the result.url which has the url string of the uploaded file but i can not access the string outside the method even when i store it in a different variable which is created outside the scope of the method.

    i have tried to print it on the console.log screen and is shows an empty string and even when i try to upload the string to the database it updates with empty string on the field. 

    I have been trying to solve this problem for over two days now. Any help would go a very long way as i am stuck with my project and have checked to find a solution everywhere online. Thank you very much.

    I use nodeJS on cloud 9 by the way.

     

    0
    Comment actions Permalink
  • Avatar
    Raz Ziv

    Hi Felix,

    As JavaScript is an asynchronous language, any logic that is based on the response of the upload function should be done within the callback function.

    When you print the value of the variable outside of the function, the code runs before the upload process is finished. Therefore, the callback function isn't called yet and the URL string is not stored in the variable at the time it is printed to the console.  

    0
    Comment actions Permalink
  • Avatar
    Landry Kapela

    HI, I'm new here and just trying cloudinary for the first time. I'm having the same issue in Android. I can upload and see the image in my dashboard but I can't get the url of the image since I upload using the String requestId = MediaManager.get().upload("myimage.jpg").dispatch()

    And where do I use this requestId?

    0
    Comment actions Permalink
  • Avatar
    Yakir Perlin

    Hi, 

    You should use the callback object, please see this:

    https://cloudinary.com/documentation/android_image_and_video_upload#callbacks

    Please let me know if it works for you.

    Best,

    Yakir

    0
    Comment actions Permalink
  • Avatar
    Aleksandar Kostadinov

    Hi @Benya,

    Based on the direct ticket you submitted to us, I believe you were able to resolve the issue.

    Will you be able to share what you changed or how you resolve the issue so that if anyone else runs into this they can try your solution?

    0
    Comment actions Permalink
  • Avatar
    benya

    Hi all,

    I'm having the same trouble using angular: 

    uploadImage(vals): Observable<any> {
    let data = vals;
    return this.http.post('https://api.cloudinary.com/v1_1/xyzsd/image/upload', data);
    }

    The image is successfully uploaded but I do not know how to retrieve url as string to save into my mySql database.

    Any help would be greatly appreciated.

    -1
    Comment actions Permalink
  • Avatar
    Raya Straus

    Hi Steve,

    Thank you for contacting us.

    Once an image is uploaded, the API call returns a Hash with content similar to that shown in the following:

    Array
    (
      [public_id] => c87hg9xfxrd4itiim3t0
      [version] => 1371995958
      [signature] => f8645b000be7d717599affc89a068157e4748276
      [width] => 864
      [height] => 576
      [format] => jpg
      [resource_type] => image
      [created_at] => 2013-06-23T13:59:18Z
      [bytes] => 120253
      [type] => upload
      [url] => http://res.cloudinary.com/demo/image/upload/v1371995958/c87hg9xfxrd4itiim3t0.jpg
      [secure_url] => https://res.cloudinary.com/demo/image/upload/v1371995958/c87hg9xfxrd4itiim3t0.jpg
    ) 

     

    You can then parse the response and save the relevant information in your database. Additionally, once the upload is finished, the uploaded image is immediately available for manipulation and delivery.

    You can read more on how to upload images here - http://cloudinary.com/documentation/php_image_upload#server_side_upload

    Hope this helps, please let me know if you have any further questions.

    Thanks,
    Raya

    -3
    Comment actions Permalink

Please sign in to leave a comment.