如何在注册新用户时将用户的个人资料图片上传到服务器?

时间:2022-02-26 16:46:25

I am developing an android app using XMPP (Openfire) . User can register new account from that app and they can set their profile picture in register form. I want to know how can I save that profile picture to Openfire server.

我正在使用XMPP(Openfire)开发一个Android应用程序。用户可以从该应用程序注册新帐户,他们可以以注册形式设置他们的个人资料图片。我想知道如何将该配置文件图片保存到Openfire服务器。

1 个解决方案

#1


You can use the vCard method that is given for Smack 4.1. Load the user's vCard when they are editing their profile information. Then, allow them to upload their avatar. Once they save it, you convert the Bitmap to a byte array, which is then sent to save vCard. Here's an example:

您可以使用为Smack 4.1提供的vCard方法。在用户编辑其个人资料信息时加载用户的vCard。然后,允许他们上传他们的头像。保存后,将Bitmap转换为字节数组,然后发送该数组以保存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);

Hope that helps

希望有所帮助

#1


You can use the vCard method that is given for Smack 4.1. Load the user's vCard when they are editing their profile information. Then, allow them to upload their avatar. Once they save it, you convert the Bitmap to a byte array, which is then sent to save vCard. Here's an example:

您可以使用为Smack 4.1提供的vCard方法。在用户编辑其个人资料信息时加载用户的vCard。然后,允许他们上传他们的头像。保存后,将Bitmap转换为字节数组,然后发送该数组以保存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);

Hope that helps

希望有所帮助