嗨我正在尝试使用codenameone从设备上传图像并将其上传到php服务器并将图像Url存储在mysql数据库中然后想要将该图像重新显示回设备上显示但是它无法正常工作 下面是我的java代码
jobIcon.addActionListener((ActionEvent en) -> {
if(Dialog.show("Camera or Gallery", "Would you like to use the camera or the gallery for the picture?", "Camera", "Gallery")) {
jobPic = Capture.capturePhoto();
if(jobPic != null)
try{
Image img = Image.createImage(jobPic);
ImageIO imgIO= ImageIO.getImageIO();
ByteArrayOutputStream out = new ByteArrayOutputStream();
imgIO.save(img, out,ImageIO.FORMAT_JPEG, 1);
bytesdata = out.toByteArray();
jobIcon.setIcon(img);
}catch(IOException err) {
ToastBar.showErrorMessage("An error occured while loading the image: " + err);
Log.e(err);
}
} else {
Display.getInstance().openGallery(ee -> {
if(ee.getSource() != null) {
try {
jobPic =(String)ee.getSource();
Image img = Image.createImage((String)ee.getSource());
ImageIO imgIO= ImageIO.getImageIO();
ByteArrayOutputStream out = new ByteArrayOutputStream();
imgIO.save(img, out,ImageIO.FORMAT_JPEG, 1);
bytesdata = out.toByteArray();
jobIcon.setIcon(img);
} catch(IOException err) {
ToastBar.showErrorMessage("An error occured while loading the image: " + err);
Log.e(err);
}
}
},Display.GALLERY_IMAGE);
我不想在此之后显示图像,如果我删除Display.GALLERY_IMAGE则显示错误, 然后我通过多部分请求发送数据
if (jobPic !=null)
{
r.addData("jobPic",bytesdata,"image/jpeg" );
}
然后使用下面的php脚本处理数据
if (isset ($_FILES["jobPic"])) {
$image = $_FILES['jobPic']['name'];
$target_path = "/uploads/";
$dir = sys_get_temp_dir();
$uid = uniqid();
$file = $uid .$image.".jpeg" ;
move_uploaded_file($_FILES["jobPic"]["tmp_name"],$target_path . $file);
$jobPic =$dir. $target_path . $file;
}else {
$jobPic = "";
然后存储在数据库中的Url看起来像这样
D:localTemp/uploads/592caa9de79fdjobPic.jpeg
在从服务器获取网址后,我无法使用此网址创建一个带有此网址的图片
请在我错误的地方纠正我或建议我使用其他替代方法
答案 0 :(得分:-2)
$ target_path =“ / uploads /”;必须为$ target_path =“ uploads /”;