$scope.retrievName = function() {
if (SearchService.getAdvflagNm()) {
$http({
params: {
"mainId": $scope.mainPR.mainInfoId
},
method: 'GET',
url: 'namePage/retrveNamePge'
})
.then(
function mySuccess(response) {
$scope.showSuggestions = false;
$scope.disOthrSec = false;
if (response.data !== "" && response.data !== undefined) {
$scope.namePageTabs = response.data;
}
SearchService.setAdvflagNm();
if (response.status == 500) {
},
function myError(response) {});
}
};
<div class="col-md-3">
<input type="file" ng-image-model file-model="tab.namePRFile" multiple />
</div>
<div ng-repeat="file in tab.namePRAttch.file track by $index">
<a ng-src="{{file}}" ng-click="openImage(this)">{{file.name}}</a><i ng-click="removePRNameFile(file)" class="btn btn-md fa fa-trash" aria-hidden="true"></i>
</div>
Set<NamePageAttchModel> atchList = result.get(i).getNameAttachments();
List<byte []> attbyArr = new ArrayList<byte[]>();
for(NamePageAttchModel m : atchList){
byte [] a = m.getAttachFile();
attbyArr.add(a);
}
viewModel.setNamePRAttch(attbyArr);
を使用すると、B64のフォーマットに変換する必要がある画像にアクセスし、そのためのエンティティを作成し、
String
型として変数IMAGEPATHを宣言します。あなたが
list = dao.getList
のようなダオ層からリストを取得していると仮定して、エンティティ名を
ImagePath
としましょう。あなたの
ImagePath
エンティティをインスタンス化し、あなたのイメージを送りたい他のすべての属性と一緒に
imagePath.setPath(b64);
としてIMAGEPATHを設定し、forループ
インサイド
String b64 = javax.xml.bind.DatatypeConverter.printBase64Binary(m.getImage());
:画像にアクセスし、同じようbase64Binaryのに変換するforループを適用します。
今
IMAGECLASSが可能してみましょうあなたは
attbyArr.add(a);
をリストに追加し、あなたのViewModel
viewModel.setNamePRAttch(attbyArr);
に追加します。
@Entity
public class ImageClass implements Serializable {
private static final long serialVersionUID = -4978144559787934722L;
@Id
@GeneratedValue(strategy=GenerationType.AUTO)
@Column(name="image_id")
private int image_id;
@Lob
@Column(name="image_content", nullable=false, columnDefinition="mediumblob")
private byte[] image;
}
が続いのImagePathクラスがあるべきよう:
public class ImagePath {
private int id;
private String imagePath;
} //generate getter setter and parametriced constructor
コントローラクラスには、
List<ImageClass> list = dao.getList();
List<ImagePath> imageList = new ArrayList<ImagePath>();
for (ImageClass m : list) {
String b64 = javax.xml.bind.DatatypeConverter.printBase64Binary(m.getImage());
ImagePath imagepath = new ImagePath();
imagepath.setId(m.getImage_id());
imagepath.setImagePath(b64);
imageList .add(imagepath);
model.addAttribute("imageList", imageList); //Or you can return it as a list that can be used in Angular
バイナリデータをダウンロードするには、 'responseType: 'blob''または' responseType:' arraybuffer''を使用します。詳細は、[MDN:XHR responseType](https://developer.mozilla.org/en-US/docs/Web/API/XMLHttpRequest/responseType)を参照してください。 – georgeawg
blobデータのみがある場合は、応答タイプ 'blob'を使用できます。しかし、私はBLOBデータと一緒に取得するための他のいくつかのフィールドも持っています。私はその部分に言及しなかった。ごめんなさい。 –
JSONレスポンスにバイナリデータを含めるには、[base64 encoding](https://en.wikipedia.org/wiki/Base64)を使用します。バイナリファイルをAPIにポストして、base64でエンコードされたデータを含むJSON応答を返す例については、[このDEMO on PLNKR](https://plnkr.co/edit/CqIixHWefjYmDfmJPbNF?p=preview)を参照してください。 – georgeawg