2012-03-13 76 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