我从html5画布中检索了base64数据uri.在我的servlet中,我想解码数据uri并将其用作输入流,如下面的"xxx"所示.以下编码是我将html5画布中的图像发布到我的Facebook帐户中.我正在使用restfb.
FacebookType publishPhotoResponse = facebookClient.publish("me/photos", FacebookType.class,
BinaryAttachment.with("test.jpeg", getClass().getResourceAsStream("xxx")),
Parameter.with("message", "Test"));
Run Code Online (Sandbox Code Playgroud)
我怎样才能做到这一点?谢谢.
更新越来越近但仍然无法正常工作!
在我的jsp中:
var d = document.getElementById('img').src;
window.location.href = "upload?src=" + d;
Run Code Online (Sandbox Code Playgroud)
在我的servlet中:
String d = req.getParameter("src");
String head = "data:image/jpeg;base64,";
String base64 = d.substring(head.length()-1);
byte[] buf = DatatypeConverter.parseBase64Binary(base64);
ByteArrayInputStream is = new ByteArrayInputStream(buf);
FacebookType publishPhotoResponse = facebookClient.publish("me/photos", FacebookType.class,
BinaryAttachment.with("test.jpeg", is),
Parameter.with("message", "Test"));
Run Code Online (Sandbox Code Playgroud)
我的编码中是否有任何错误,因为它似乎在servlet中的某处出现错误.我无法查看在服务器上运行的错误.
我正试图从我的朋友列表中检索20条记录,其名称以"J"开头.但是,我意识到JSTL没有中断.所以我尝试使用计数来跟踪记录.我遇到错误'PWC6031:Unterminated <c:set tag'
<c:set var="count" value="0" scope="page">
<c:forEach items="${friendsList}" var="user">
<c:if test="${count < 20}">
<c:set var="string1" value="${fn:substring(user.name, 0, 1)}" />
<c:if test="${fn:startsWith(string1,'J')}">
<tr>
<td><c:out value="${user.name}" /></td>
<td><img src='https://graph.facebook.com/<c:out value="${user.id}"/>/picture' />
</td>
</tr>
</c:if>
</c:if>
<c:set var="count" value="${count + 1}" scope="page"/>
</c:forEach>
Run Code Online (Sandbox Code Playgroud)
有没有办法可以从count变量中检索值?如果没有,是否有另一种方法可以突破循环以达到我想要的效果?谢谢.
在解决了我遇到的错误之后,我设法利用count变量来列出我想要的内容.我在原始编码中混淆了"计数"编码的顺序.这就是我现在所拥有的,正在努力,感谢大家的帮助!
<c:set var="count" value="0" scope="page" />
<c:forEach items="${friendsList}" var="user">
<c:if test="${count < 20}">
<c:set var="string1" value="${fn:substring(user.name, 0, 1)}" />
<c:if test="${fn:startsWith(string1,'J')}">
<tr>
<td><c:out value="${user.name}" /></td>
<td><img src='https://graph.facebook.com/<c:out value="${user.id}"/>/picture' /></td>
</tr>
<c:set var="count" value="${count + 1}" scope="page" />
</c:if> …Run Code Online (Sandbox Code Playgroud)