2017-08-10 28 views
1

如果我使用我的設備錄製短於10秒的視頻並將其上傳到我的Parse數據庫,那麼Parse Server Android SDK有一個奇怪的問題,它工作正常。 視頻文件超過10秒時給我這個錯誤消息:無法上傳超過10秒的視頻文件 - 無法對未保存的ParseFile進行編碼

java.lang.IllegalStateException:無法編碼未保存ParseFile

這裏是我的代碼:

// Create ParseObject 
      final ParseObject vObj = new ParseObject(Configs.VIDEOS_CLASS_NAME); 

      pd.setMessage("Please wait until your video is uploading..."); 
      pd.show(); 

      vObj.put(Configs.VIDEOS_TITLE, titleTxt.getText().toString()); 
      vObj.put(Configs.VIDEOS_IS_REPORTED, false); 
      vObj.put(Configs.VIDEOS_COLOR, colorNr); 
      vObj.put(Configs.VIDEOS_VIEWS, 0); 
      vObj.put(Configs.VIDEOS_USER_POINTER, ParseUser.getCurrentUser()); 
      vObj.put(Configs.VIDEOS_CATEGORY, selectedCategory); 

      // Saving block 
      vObj.saveInBackground(new SaveCallback() { 
       @Override 
       public void done(ParseException e) { 
        if (e == null) { 
         Log.i("log-", "DATA SAVED! - SAVING THUMBNAIL..."); 

         // Get video thumbnail Bitmap and save it 
         try { thumbnailBm = BitmapFactory.decodeStream(SubmitVideo.this.openFileInput("imagePassed")); 
          Log.i("log-", "THUMBNAIL BITMAP: " + thumbnailBm); 

          // Save video thumbnail 
          ByteArrayOutputStream st = new ByteArrayOutputStream(); 
          thumbnailBm.compress(Bitmap.CompressFormat.JPEG, 50, st); 
          byte[] byteArr = st.toByteArray(); 
          ParseFile thumbFile = new ParseFile("thumb.jpg", byteArr); 
          vObj.put(Configs.VIDEOS_THUMBNAIL, thumbFile); 

          vObj.saveInBackground(new SaveCallback() { 
           @Override 
           public void done(ParseException e) { 
            if(e == null) { 
             Log.i("log-", "THUMBNAIL SAVED! - SAVING VIDEO..."); 

             // Save video 
             if (videoURI != null) { 
              ParseFile videoFile = new ParseFile("video.mp4", convertVideoToBytes(videoURI)); 
              vObj.put(Configs.VIDEOS_VIDEO, videoFile); 
              Log.i("log-", "VIDEO URI TO SUBMIT: " + videoURI); 

              vObj.saveInBackground(new SaveCallback() { 
               @Override 
               public void done(ParseException e) { 
                if (e == null) { 
                 pd.dismiss(); 
                 Log.i("log-", "SUCCESS! "); 

                // error on saving 
                } else { 
                 Configs.simpleAlert(e.getMessage(), SubmitVideo.this); 
                 pd.dismiss(); 
              }}}); 
             } 


            // error on saving 
            } else { 
             Configs.simpleAlert(e.getMessage(), SubmitVideo.this); 
             pd.dismiss(); 
          }}}); 

         } catch (FileNotFoundException err) { err.printStackTrace(); } 


        // error on saving 
        } else { 
         Configs.simpleAlert(e.getMessage(), SubmitVideo.this); 
         pd.dismiss(); 
      }}}); 

任何人知道爲什麼發生? 謝謝!

回答

1
var api = new ParseServer({ 
... 
    maxUploadSize: "300mb" 
...}); 

也許你需要改變你的nginx/apache配置允許它。

在nginx的:client_max_body_size 300M;

+0

感謝您的回答,不幸的是我沒有知道nginx是什麼...如果你的意思是這樣的話:https://www.nginx.com/resources/wiki/不,我沒用它 – cubycode

+0

你能改變你的服務器配置嗎?我認爲最大的默認大小是20mb –

+0

似乎Android的解析SDK沒有文件大小限制了:https://github.com/parse-community/Parse-SDK-Android/pull/462/files – cubycode

2

視頻可能太大而無法一次上傳。 您應該使用的multipart ..我有同樣的問題,同時上載高分辨率圖像.. Uploading High res images in android 修改此代碼爲視頻

+0

謝謝,問題是,我不使用PHP/MySQL,但解析服務器SDK,所以我不認爲我可以使用多代碼片段在這種情況下... – cubycode

+0

你在用nginx嗎? –

+0

我不知道nginx是什麼,對不起...如果你的意思是這樣的話:https://www.nginx.com/resources/wiki/不,我沒有使用它 – cubycode

相關問題