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();
}