[英]save and retrieve image from database using spring mvc and hibernate Rest services
[英]how to send image through android REST Web services and save it and retrieve from mysql database
我是Android開發的新手,我只是想知道如何通過android REST Web服務發送圖像並保存圖像並從MySQL數據庫檢索
您可以將位圖圖像編碼為Base64,因此將圖像編碼為字符串。 您可以使用REST API發送該字符串並將其保存到數據庫。 稍后,當您要顯示它時,再次下載並將其解碼為Bitmap。 這是進行編碼/解碼的方法。
根據我的經驗,客戶端將image-string
(編碼的圖像字節數組)發送到服務器,然后將其保存到數據庫中。 為了顯示圖像,客戶端從服務器獲取image-string
,並將解碼后的image-string
到字節數組。 嘗試顯示image byte array
。
public static String encodeImage(byte[] imageByteArray) {
return Base64.encodeBase64URLSafeString(imageByteArray);
}
public static byte[] decodeImage(String imageDataString) {
return Base64.decodeBase64(imageDataString);
}
使用org.apache.commons.codec.binary.Base64
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.