简体   繁体   English

字符串Base64或物理映像文件

[英]String Base64 or physical image file

I'm coding an Android app and in user signup he can select a image to be set in his profile. 我正在编写一个Android应用程序,在用户注册时,他可以选择要在个人资料中设置的图片。 One of the feature is select friends by contact list where has a picture, name and others information about the contact. 功能之一是通过联系人列表选择朋友,其中包含图片,姓名和其他有关该联系人的信息。 I'm using Json as result set of my request and it returns me an arraylist of users. 我使用Json作为请求的结果集,它返回了一个用户数组列表。

I don't know what's the best practice for it, do I have to upload the Base64 String to server, decode it to an image file and store it in directory and when request comes I send an URL image or do I have to send Base64 String to a database field end when request come I return the ArrayList and decode these String to a image file and load it inside my ImageView ? 我不知道什么是最佳实践,我是否必须将Base64字符串上载到服务器,将其解码为图像文件并将其存储在目录中,并且当请求到来时我发送URL图像还是必须发送Base64当请求到来时,字符串到数据库字段结束。我返回ArrayList并将这些字符串解码为图像文件,然后将其加载到ImageView

Can someone help me understand the difference of theses two ways? 有人可以帮助我理解这两种方式的区别吗?

base64 encoded data will be bigger than raw data and then you yet need to decode it on client. base64编码的数据将大于原始数据,然后您仍需要在客户端上对其进行解码。 So what's the point? 那有什么意义呢? Serve "normal" images, so client app does not need to do any "magic" to display it. 提供“正常”图片,因此客户端应用无需执行任何“魔术”即可显示。 Also you'd be able to use classes like Glide or Picasso to and delegate loading/caching etc to them /wo any hassle 另外,您还可以使用Glide或Picasso之类的类,并将加载/缓存等委托给它们/避免任何麻烦

IMHO it might be easier to go with base64 when transferring data to client using JSON. 恕我直言,使用JSON将数据传输到客户端时,使用base64可能更容易。 Here is one popular answer that also agrees. 这是一个也同意的流行答案

But if Android apps allow you to reference the URL of an image (eg http://domain/path/img.png ) then I would just store the URL in the DB and pass that URL from the server to the Andriod app. 但是,如果Android应用程序允许您引用图像的URL(例如, http://domain/path/img.png ),那么我只会将该URL存储在DB中,然后将该URL从服务器传递给Andriod应用程序。 I think JavaFX's ImageView allows this. 我认为JavaFX的ImageView允许这样做。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM