无法上传超过10秒的视频文件 - 无法对未保存的ParseFile进行编码
问题描述:
如果我使用我的设备录制短于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();
}}});
任何人知道为什么发生? 谢谢!
答
var api = new ParseServer({
...
maxUploadSize: "300mb"
...});
也许你需要改变你的nginx/apache配置允许它。
在nginx的:client_max_body_size 300M;
答
视频可能太大而无法一次上传。 您应该使用的multipart ..我有同样的问题,同时上载高分辨率图像.. Uploading High res images in android 修改此代码为视频
感谢您的回答,不幸的是我没有知道nginx是什么...如果你的意思是这样的话:https://www.nginx.com/resources/wiki/不,我没用它 – cubycode
你能改变你的服务器配置吗?我认为最大的默认大小是20mb –
似乎Android的解析SDK没有文件大小限制了:https://github.com/parse-community/Parse-SDK-Android/pull/462/files – cubycode