Saving multiple ParseFile objects in one ParseObject

ANDROID

This is how I store the ParseFile List in 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(); 

after this call, it does not show the inserted row in the data browser, although it shows the number of rows from 1 in the table

This is how I retrieve it and get the first image from the list

 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); } 

I can get all the columns of the String, but for the column "mediaFiles" when I getData () I get thisexception. com.parse.ParseException: The target host must not be null or specified in parameters.

I noticed that in ParseFile the data and url are null.

Can someone please show me the code on how to store and retrieve multiple ParseFile objects in one ParseObject?

+6
source share
4 answers

Try loading ParseFiles using the save method before linking them to the Parse Object.

+3
source

Try to make it as a downloadable image one by one,

  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(); } 
0
source

Cover byte [] bitmapdata = pFile.getData (); line of code in try catch. It worked for me!

0
source
 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) { } }); 

Multiple loading is performed above the code, but ParseObject is called only after two save () methods. Due to the fact that the two user interfaces of the save method are stuck. How to fix it!

-1
source

Source: https://habr.com/ru/post/949381/


All Articles