2013-10-22 95 views
3

我的幾個時間軸項目設計需要多個圖像,但我很難可靠地連接它們。 timeline.insert函數似乎只允許在插入時間軸項目後插入一個附件並插入附件,有時會導致圖像不被渲染。什麼是附加多個圖像的最佳方式?

我也嘗試在時間線項目本身上使用setAttachments,但它似乎並沒有實際上傳插入項目時的附件。使用下面的代碼我傾向於得到混合的結果。有時會起作用,有時候它無法呈現圖像。似乎與收到它後等待查看通知的時間有多長時間的關聯,如果我查看它太快,它將無法完全呈現。

有沒有人有任何想法或建議,我怎麼能克服這個或看到我做錯了什麼?

//CardFactory.java - Create TimelineItem with attachment list 
public static TimelineItem getConceptCard(String conceptImage) { 
    TimelineItem timelineItem = new TimelineItem(); 
    timelineItem.setHtml("<article class=\"photo\">\n <img src=\"attachment:0\" width=\"100%\" height=\"100%\">\n <div class=\"photo-overlay\"/>\n <section>\n <p class=\"text-auto-size\">Test</p>\n </section>\n</article>\n"); 
    List<Attachment> attachments = new ArrayList<Attachment>(); 
    Attachment img1 = new Attachment(); 
    img1.setId("backImage"); 
    img1.setContentType("image/jpeg"); 
    img1.setContentUrl(WebUtil.buildStaticImgUrl("cardconcepts/" + conceptImage + ".JPG")); 
    attachments.add(img1); 
    timelineItem.setAttachments(attachments); 
    timelineItem.setNotification(new NotificationConfig().setLevel("DEFAULT")); 
    return timelineItem; 
} 




//MainServlet.java - Send TimelineItem on button press 
} else if (req.getParameter("operation").equals("insertConceptCard")) { 
    TimelineItem timelineItem = CardFactory.getConceptCard(req.getParameter("conceptCard")); 
    MirrorClient.insertTimelineCard(credential, timelineItem); 




//MirrorClient.java - Insert TimelineItem with multiple attachments 
public static void insertTimelineCard(Credential credential, TimelineItem item) throws IOException { 
    Mirror.Timeline timeline = getMirror(credential).timeline(); 
    TimelineItem timelineItem = timeline.insert(item).execute(); 
    for(Attachment TAttach : item.getAttachments()){ 
     InputStreamContent mediaContent = new InputStreamContent(TAttach.getContentType(), new URL(TAttach.getContentUrl()).openStream()); 
     timeline.attachments().insert(timelineItem.getId(), mediaContent).execute(); 
    } 

回答

0

我不知道是否有可能給您的要求,但如果附件是公衆形象,你實際上並不需要連接它們。您可以使用正常http URL的img標籤。我的經驗是,這些獲取速度相當快,如果經常使用它們,就會被緩存,即使它們沒有立即渲染,也會正確渲染。 (即使你的需求需要保持這些更私密,你可能希望使用標準的圖像獲取與某種nonce,而不是試圖附加他們。我意識到這並不完全回答你的問題,但它可能會是一個有用的解決方法。)

相關問題