2013-10-22 10 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

귀하의 요구 사항에 따라 가능할지 모르겠지만 첨부 파일이 공개 이미지 인 경우 실제로 첨부 할 필요가 없습니다. img 태그는 일반적인 http URL과 함께 사용할 수 있습니다. 내 경험에 의하면 이러한 것들은 상당히 빨리 가져오고 자주 사용하면 캐싱되며 즉시 렌더링되지 않더라도 제대로 렌더링됩니다.

(요구 사항이 더 개인적으로 유지해야하는 경우에도 표준 이미지 가져 오기를 첨부하는 대신 일종의 nonce로 사용하는 것이 좋습니다.이 질문에 대한 답변은 분명하지 않지만 유용한 해결 방법이 될 수 있습니다.)

관련 문제