通过Web服务将映像从Java桌面应用程序上载到PHP-Server

时间:2015-12-15 06:27:00

标签: java php web-services

  1. 选择图像表单系统..

    JFileChooser chooser = new JFileChooser();
    chooser.showOpenDialog(null);
    File f = chooser.getSelectedFile();
    String filename = f.getAbsolutePath();
    String imageName=f.getName();
    
    try {
        ImageIcon ii;
        ii = new ImageIcon( ImageIO.read(new File(f.getAbsolutePath())));
        jLabel2.setIcon(ii);
    } catch (Exception ex) {
        ex.printStackTrace();
    }
    
  2. 通过Web服务将数据上传到服务器

    List<NameValuePair> nvps = new ArrayList<NameValuePair>();
    nvps.add(new BasicNameValuePair("user_id", AuthConstants.id));
    nvps.add(new BasicNameValuePair("profile_pic",imageName));
    nvps.add(new BasicNameValuePair("profile_pic_path",filename));
    
    try {
        StringBuilder s = (StringBuilder) HttpWebService.postWebService(nvps, "services", "setting_update");
        JOptionPane.showMessageDialog(null,"pic data  :"  );
        System.out.println("File uploaded: " );
        JOptionPane.showMessageDialog(null,"profile pic upload done (y)");
    } catch (Exception e) {
        JOptionPane.showMessageDialog(null, e.getMessage());
    }
    

0 个答案:

没有答案