2014-12-31 65 views
1

parse.com提供了一種在離線模式下使用object.saveEventually()保存ParseObject的方法。調用..這將對象存儲在本地dataStore中,除非與服務器同步完成。Parse.com:Android如何在ParseObject中以離線模式存儲Image ParseFile

問題是,我不能存儲Parsefile像解析對象saveEventully();方法

這裏是我的代碼:

// Locate the image in res > drawable-hdpi 
         Bitmap bitmap = Util.convertBitmap(ImgLocalPath); 
         // Convert it to byte 
         ByteArrayOutputStream stream = new ByteArrayOutputStream(); 
         // Compress image to lower quality scale 1 - 100 
         bitmap.compress(Bitmap.CompressFormat.JPEG, 100, 
           stream); 
         byte[] image = stream.toByteArray(); 
         // Create the ParseFile 
         final ParseFile file = new ParseFile("NC_Image", 
           image); 

         // Upload the image into Parse Cloud 
         file.saveInBackground(new SaveCallback() { 

          @Override 
          public void done(ParseException arg0) { 

           final ParseObject ncImagesObj = new ParseObject("NCImages"); 


           ParseObject userObject = ParseObject.createWithoutData("AppUsers", userId); 
           ncImagesObj.put("user", userObject); 
           ncImagesObj.put("comment",obj.getComment()); 
           ncImagesObj.put("UserType", UserType); 

           ncImagesObj.saveEventually(new SaveCallback() { 

            @Override 
            public void done(ParseException arg0) { 

              ncImagesObj.put("image", file); 
              ncImagesObj.saveInBackground(); 

              System.out 
                .println("Images Save...."); 

            } 
           });         
          } 
         }, new ProgressCallback() { 

          @Override 
          public void done(Integer arg0) { 
           // TODO Auto-generated method stub 

          } 
         }); 

但是這不會工作 只有「NC_Image」的parseObject創建,但它不能把圖像ParseFile到該對象。

任何人有解決方案...... plz幫助我找到了解決辦法

+0

也許這個答案將幫助您:http://stackoverflow.com/a/26978612 –

回答

2

我錯了它不可能保存/在離線模式下創建分析文件,

因爲解析文件生成唯一對象ID上傳文件字節後的文件。

這就是爲什麼它是不可能的,但

爲了解決這個問題,我已經在本地存儲圖像和背景,創造解析文件(在服務器上上傳)後,當網絡上。

感謝您的幫助.. :)

相關問題