无法上传超过 10 秒的视频文件 - 无法对未保存的 ParseFile 进行编码
Unable to upload a 10+ second video file - Unable to encode an unsaved ParseFile
我在使用 Parse Server Android SDK 时遇到了一个奇怪的问题,如果我用我的设备录制一个短于 10 秒的视频并将其上传到我的 Parse 数据库,它就可以正常工作。
超过 10 秒的视频文件给我这个错误信息:
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();
}}});
有人知道为什么会这样吗?
谢谢!
视频可能太大,无法一次性上传。
你应该使用 multiparts ..我在上传高分辨率图像时遇到了同样的问题.. Uploading High res images in android
为视频修改这段代码
var api = new ParseServer({
...
maxUploadSize: "300mb"
...});
可能您需要更改 nginx/apache 配置以允许它。
在 nginx 上:client_max_body_size 300M;
我在使用 Parse Server Android SDK 时遇到了一个奇怪的问题,如果我用我的设备录制一个短于 10 秒的视频并将其上传到我的 Parse 数据库,它就可以正常工作。 超过 10 秒的视频文件给我这个错误信息:
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();
}}});
有人知道为什么会这样吗? 谢谢!
视频可能太大,无法一次性上传。 你应该使用 multiparts ..我在上传高分辨率图像时遇到了同样的问题.. Uploading High res images in android 为视频修改这段代码
var api = new ParseServer({
...
maxUploadSize: "300mb"
...});
可能您需要更改 nginx/apache 配置以允许它。
在 nginx 上:client_max_body_size 300M;