这就是我将ParseFile List存储到ParseObject
的方法ParseObject pObject = new ParseObject();
ArrayList<ParseFile> pFileList = new ArrayList<ParseFile>();
for (String thumbPath : thumbList) {
byte[] imgData = convertFileToByteArray(thumbPath);
ParseFile pFile = new ParseFile("mediaFiles",imgData);
pFileList.add(pFile);
}
pObject.addAll("mediaFiles", pFileList);
pObject.saveEventually();
在此调用之后它没有在数据浏览器中显示插入的行,尽管它在表中显示了rowcount为1
这就是我检索它并从列表中获取第一张图片的方式
List<ParseFile> pFileList = (ArrayList<ParseFile>) pObject.get("mediaFiles");
if (!pFileList.isEmpty()) {
ParseFile pFile = pFileList.get(0);
byte[] bitmapdata = pFile.getData(); // here it throws error
bitmap = BitmapFactory.decodeByteArray(bitmapdata, 0, bitmapdata.length);
}
我能够检索所有String列,但是对于“mediaFiles”列,在执行getData()时,我得到了这个例外。 com.parse.ParseException:目标主机不能为空,或者在参数中设置。
我观察到在ParseFile中,数据和网址为空。
有人可以告诉我如何将多个ParseFile对象存储和检索到单个ParseObject中的代码吗?
答案 0 :(得分:3)
尝试使用save方法上传ParseFiles,然后再将它们与Parse Object相关联。
答案 1 :(得分:0)
尝试一个接一个地上传图片,
public void UploadImageToParse(String img_path, final String filedName, String Filename) {
//String img_path = Environment.getExternalStorageDirectory().getAbsolutePath() + "/" + "P200913_1908.jpg";
final File file = new File(img_path);
try {
FileInputStream fileInputStream = new FileInputStream(file);
Bitmap bitmap = BitmapFactory.decodeStream(fileInputStream);
ByteArrayOutputStream baos = new ByteArrayOutputStream();
bitmap.compress(Bitmap.CompressFormat.JPEG, 100, baos);
byte[] image_array = baos.toByteArray();
final ParseFile parsefile = new ParseFile(Filename, image_array);
parsefile.saveInBackground(new SaveCallback() {
@Override
public void done(ParseException e) {
if (e != null) {
} else {
frameInfo.put(filedName, parsefile);
frameInfo.saveInBackground(new SaveCallback() {
@Override
public void done(ParseException e) {
if (e == null) {
DebugLog.e("" + e);
} else {
fileUploadStatusUpdater.onFailure();
DebugLog.e("File Upload Fail");
}
}
});
/*ParseUser user = ParseUser.getCurrentUser();
user.put(filedName, parsefile);
user.saveInBackground(new SaveCallback() {
@Override
public void done(ParseException e) {
Log.e("", "" + e);
}
});*/
}
}
}, new ProgressCallback() {
@Override
public void done(Integer integer) {
if (integer == 100) {
DebugLog.e("File Upload Completed");
fileUploadStatusUpdater.onSuccess();
}
}
});
} catch (Exception e) {
DebugLog.e("Fis" + e);
fileUploadStatusUpdater.onFailure();
}
答案 2 :(得分:0)
覆盖 byte [] bitmapdata = pFile.getData(); try catch下的代码行。它对我有用!
答案 3 :(得分:-1)
final ParseFile parseFile1 = new ParseFile("poll_image1.jpg",scaleImage("poll_image1",imageList.get(contestImage1.getId())));
final ParseFile parseFile2 = new ParseFile("poll_image2.jpg",scaleImage("poll_image2",imageList.get(contestImage2.getId())));
parseFile1.save(); parseFile2.save();
List<ParseFile> listOfFiles = new ArrayList<ParseFile>();
listOfFiles.add(parseFile1);
listOfFiles.add(parseFile2);
ParseObject jobApplication = new ParseObject("Poll");
jobApplication.put("poll_question", contestQuestion.getText().toString());
jobApplication.put("poll_type_id", 1);
ParseUser currentUser = ParseUser.getCurrentUser();
jobApplication.put("user", currentUser);
jobApplication.put("parseFile", listOfFiles);
jobApplication.saveInBackground(new SaveCallback() {
@Override
public void done(ParseException arg0) {
}
});
上面的代码执行多上传,但ParseObject只在两个save()方法之后调用。因为两个保存方法UI得到了Stuck。如何解决它!