我试图以html格式上传带有一些文字和数字类型的图片。在前端,我在后端使用angularjs和rest jersey。我的问题是当我试图坚持我的对象" Vehicule"它包含一个byte []图像。为此我在角度控制器中使用资源指令,但是当我尝试提交表单时出现此错误"无法将VALUE_STRING解码为base64(MIME-NO-LINEFEEDS):非法字符&# 39;:' (代码0x3a)在base64内容"我有任何想法,因为我是角度和休息球衣的初学者。为此,这是我的代码:
@JsonIgnoreProperties(ignoreUnknown = true)
@Entity
public class Vehicule implements Serializable {
private static final long serialVersionUID = 1L;
@Id
@GeneratedValue(strategy = GenerationType.IDENTITY)
private Long id;
@Column
String marque;
@Column
String nom;
@Column
String numMat;
@Column
Long nbChevaux;
@Column
Long annee;
//@Type(type="org.hibernate.type.StringClobType")
@Column(length=100000)
byte[] image=null;
@Column(unique=true)
Long marqueur=null;
public Long getMarqueur() {
return marqueur;
}
public void setMarqueur(Long marqueur) {
this.marqueur = marqueur;
}
public Long getAnnee() {
return annee;
}
public void setAnnee(Long annee) {
this.annee = annee;
}
public byte[] getImage() {
return image;
}
public void setImage(byte[] image) {
this.image = image;
}
public Long getId() {
return id;
}
public void setId(Long id) {
this.id = id;
}
public String getMarque() {
return marque;
}
public void setMarque(String marque) {
this.marque = marque;
}
public String getNom() {
return nom;
}
public void setNom(String nom) {
this.nom = nom;
}
public String getNumMat() {
return numMat;
}
public void setNumMat(String numMat) {
this.numMat = numMat;
}
public Long getNbChevaux() {
return nbChevaux;
}
public void setNbChevaux(Long nbChevaux) {
this.nbChevaux = nbChevaux;
}
@Override
public int hashCode() {
final int prime = 31;
int result = 1;
result = prime * result + ((id == null) ? 0 : id.hashCode());
return result;
}
@Override
public boolean equals(Object obj) {
if (this == obj)
return true;
if (obj == null)
return false;
if (!(obj instanceof Vehicule))
return false;
Vehicule other = (Vehicule) obj;
if (id == null) {
if (other.id != null)
return false;
} else if (!id.equals(other.id))
return false;
return true;
}
}
@Component
@Path("/vehicules")
public class Vehicules {
private final Logger logger = LoggerFactory.getLogger(this.getClass());
@Autowired
private VehiculeDao vehiculeDao;
@GET
@Produces(MediaType.APPLICATION_JSON)
public List<Vehicule> vehiculesList()
{
return vehiculeDao.getAll();
}
@POST
@Produces(MediaType.APPLICATION_JSON)
@Consumes(MediaType.APPLICATION_JSON)
public Vehicule createVehicule(Vehicule vehicule)
{
this.logger.info("create(): " + vehicule);
return this.vehiculeDao.save(vehicule);
}
}
function CreateVehiculeController($scope, $routeParams, $location, VehiculesService)
{
$scope.vehicule = new VehiculesService();
$scope.save = function() {
$scope.vehicule.$save(function() {
$location.path('/');
}
答案 0 :(得分:2)
使用window.btoa(your_image_as_binary_string);
作为提交给控制器的值。
https://developer.mozilla.org/en-US/docs/Web/API/WindowBase64.btoa