2012-03-13 77 views
0

我正在使用黑莓webworks我想上传图像从相机到php webserver我在uri中获取图像,它显示正确,但我不知道如何将图像上传到服务器请帮忙。从黑莓WebWorks SDK相机到PHP文件服务器的帖子图像

文件URI 文件://目录/图片名称

我使用黑莓WebWorks的摄像头API这段代码

function takePicture() { 
          try { 
           blackberry.media.camera.takePicture(photoTaken, closedCB, errorCB); 
          } catch (e) { 
           //alert("Error in supported: " + e); 
          } 
         } 

         function successCB(filePath) { 

          var file = "file://" + filePath; 
          $("#myfileCam").val(file); 
          $("#imgPic").show(); 
          $("#imgPic").attr("src", file); 

         } 

         function photoTaken(filePath) { 

          var img = new Image(); 
          img.src = "file://" + filePath; 
          img.width = Math.round(screen.width/2); 
          document.getElementById("path").appendChild(img); 
          var html = "<input type='file' name='myfile' id='myfile' value='file://" + filepath + "' />"; 
          document.getElementById("fileup").innerHTML = html; 
          //$("#fileup").html(); 
          $("#myfileCam").val("file://" + filePath); 

         } 

         function closedCB() { 
          // alert("Camera closed event"); 
         } 

         function errorCB(e) { 
          alert("Error occured: " + e); 
         } 
+0

从图像中获取图像数据并将数据发送到服务器。 – Signare 2012-03-13 08:39:29

+0

你有什么特别的例子吗?谢谢 – 2012-03-13 12:01:06

回答

0
FileConnection fc= (FileConnection)Connector.open(filePath); 
InputStream is=fc.openInputStream(); 
        byte[] ReimgData = IOUtilities.streamToBytes(is); 
        EncodedImage encode_image =EncodedImage.createEncodedImage(ReimgData, 0, (int)fc.fileSize()); 
        JPEGEncodedImage encoder=JPEGEncodedImage.encode(encode_image.getBitmap(),50); 
        byte[] array=encoder.getData(); 
        // Decodes the image represented by this EncodedImage and returns a Bitmap 
        int length=array.length; 
        ByteArrayOutputStream byteArrayOutputStream = new ByteArrayOutputStream(length); 
        Base64OutputStream base64OutputStream = new Base64OutputStream(byteArrayOutputStream); 
        try{ 
            base64OutputStream.write(array, 0, length); 
            base64OutputStream.flush(); 
            base64OutputStream.close(); 
           } 
            catch (IOException ioe){ 
            //Dialog.alert("Error in encodeBase64() : "+ioe.toString()); 
            System.out.println("Error in encodeBase64() : "+ioe.toString()); 

           } 


data = Base64InputStream.decode(byteArrayOutputStream.toString()); 
+0

对不起,我正在使用黑莓webworks并仅使用javascript。 – 2012-03-14 02:13:16

0

使用PhoneGap的黑莓WebWorks的我有同样的问题,我解决了使用这个API。

http://docs.phonegap.com/en/1.5.0/phonegap_file_file.md.html#FileTransfer这里你需要的一切。

您需要做的唯一事情就是将phonegap jar文件放在ext文件夹中,然后调用config.xml文件的权限添加此功能(phonegap),然后调用它。

我希望这个工作给你,它对我有用。

+0

http://justpaste.it/vrg - 这里和例子 – 2012-04-09 22:06:27