注册新用户时如何上传用户头像到服务器?
Posted
技术标签:
【中文标题】注册新用户时如何上传用户头像到服务器?【英文标题】:How can I upload user's profile picture to server when registering new user ? 【发布时间】:2015-05-08 14:49:17 【问题描述】:我正在使用 XMPP (Openfire) 开发一个 android 应用程序。用户可以从该应用程序注册新帐户,他们可以在注册表单中设置他们的个人资料图片。我想知道如何将头像保存到 Openfire 服务器。
【问题讨论】:
【参考方案1】:您可以使用为 Smack 4.1 提供的 vCard 方法。在用户编辑个人资料信息时加载用户的 vCard。然后,允许他们上传他们的头像。一旦他们保存它,您将位图转换为字节数组,然后将其发送到保存 vCard。这是一个例子:
// Let the user pick their avatar
Bitmap bitmap;
// Take the avatar and convert it into a byte array:
ByteArrayOutputStream stream = new ByteArrayOutputStream();
// 90 refers the the compression quality. For PNG, the quality is ignored
bitmap.compress(Bitmap.CompressFormat.JPEG, 90, stream);
byte[] avatarByte = stream.toByteArray();
// Once you get the byte array from the image, set the byte array to the vCard avatar
vCard.setAvatar(avatarByte);
// Then you can save the vCard details
vCardManager.saveVCard(vCard);
希望有帮助
【讨论】:
以上是关于注册新用户时如何上传用户头像到服务器?的主要内容,如果未能解决你的问题,请参考以下文章
Spring Cloud Feign Client 实现MultipartFile上传文件功能