2013-07-26 55 views
0

我正在使用Appcelerator Cloud Services將圖片上傳到雲端,並希望將其恢復爲各種大小。上傳工作正常,但我沒有收回照片。我在JSON響應得到urls從json響應解析圖像Appcelerator Cloud?

這裏是我的代碼:

Cloud.Photos.show({ 
     photo_id: pid 
    }, function (e) { 
     if (e.success) { 
      var photo = e.photos[0]; 
      waitDialog.hide(); 
      alert('Success:\n' + 
       'id: ' + photo.id + '\n' + 
       'filename: ' + photo.filename + '\n' + 
       'updated_at: ' + photo.updated_at + '\n' + 
       'urls: ' + photo.urls); 

       alert(photo.urls.square); 
       var image2 = photo.urls.square.toImage(); 

       var squareImage = Ti.UI.createImageView({ 
        top: "10dp", 
        left: "10dp", 
        image: image2, 
        height: Titanium.UI.SIZE, 
        width: Titanium.UI.SIZE 
       }); 

       $.index.add(squareImage); 

     } else { 
      alert('Error:\n' + 
       ((e.error && e.message) || JSON.stringify(e))); 
     } 
    }); 

和我得到這樣一個JSON響應(這是不是原裝的,因爲我在設備測試它)

{ 
    "meta": { 
    "status":"ok", 
    "code":200, 
    "method_name":"showPhoto" 
    }, 
    "response": { 
    "photos": [ 
     { 
     "id":"4d51d4186f70952d4c000006", 
     "filename":"photo.jpg", 
     "size":584344, 
     "collection_name":"default", 
     "md5":"589b8ad43ed20bf8e622d719642bc939", 
     "created_at":"2011-02-08T23:39:04+0000", 
     "updated_at":"2011-02-08T23:39:08+0000", 
     "processed":true, 
     "content_type":"image/jpeg", 
     "urls": { 
      "square":"http://storage.appcelerator.com/c3e1d292cb79ba7b9783d6cd45344719/photos/4d51d4186f70952d4c000006/photo_square.jpg", 
      "thumb":"http://storage.appcelerator.com/c3e1d292cb79ba7b9783d6cd45344719/photos/4d51d4186f70952d4c000006/photo_thumb.jpg", 
      "small":"http://storage.appcelerator.com/c3e1d292cb79ba7b9783d6cd45344719/photos/4d51d4186f70952d4c000006/photo_small.jpg", 
      "medium_500":"http://storage.appcelerator.com/c3e1d292cb79ba7b9783d6cd45344719/photos/4d51d4186f70952d4c000006/photo_medium_500.jpg", 
      "medium_640":"http://storage.appcelerator.com/c3e1d292cb79ba7b9783d6cd45344719/photos/4d51d4186f70952d4c000006/photo_medium_640.jpg", 
      "large":"http://storage.appcelerator.com/c3e1d292cb79ba7b9783d6cd45344719/photos/4d51d4186f70952d4c000006/photo_large.jpg", 
      "original":"http://storage.appcelerator.com/c3e1d292cb79ba7b9783d6cd45344719/photos/4d51d4186f70952d4c000006/photo_original.jpg" 
     } 
     } 
    ] 
    } 
} 

我想從urls得到所有圖像。

我需要解析它還是我需要做的任何其他事情?誰能告訴我如何做到這一點?

謝謝:)

回答

0

分配照片這樣

squareImage.image =photo.urls.square; 
+0

是的,我想這一點。事情是,'photo.urls.square'沒有返回任何東西。 – Porwal

+0

這是因爲圖像尚未處理。看看文檔。 http://docs.appcelerator.com/cloud/latest/#!/guide/photosizes-section-3您需要指定您想要同步的大小,以便立即可用 –