简体   繁体   中英

How to upload multiple images on Parse?

I need help with Parse Android API and images uploading/updating. User in my app can create event that has 1 or more images related to that event. So, this images are stored as array object that have parse files.

User can edit images that he added for that event. So, user might want to delete image or to add a new image. So, there I have problem, how I can edit array to delete specific image.

My idea was to download all images on the phone, and when user add/delete image update it locally and then upload again all images to Parse and update that array of images, but it seems that is not working properly, since I get only one image uploaded.

How I can solve this problem, any idea is appreciated.

for (int i = 0; i < ImagesSingleton.getInstance().getBytesList().size(); i++) {
    String fileName = FileHelper.getFileName(getActivity(), ImagesSingleton.getInstance().getUrisList().get(i), "image");
    byte[] b = ImagesSingleton.getInstance().getBytesList().get(i);
    final ParseFile imgFile = new ParseFile(fileName, ImagesSingleton.getInstance().getBytesList().get(i));
    imgFile.saveInBackground(new SaveCallback() {
        @Override
        public void done(com.parse.ParseException e) {
            if (e == null) {
                listOfFiles.add(imgFile);
                if (listOfFiles.size() == ImagesSingleton.getInstance().getUrisList().size()) {
                    offer.put(ParseConstants.OFFER_PICTURES, listOfFiles);
                    offer.saveInBackground(new SaveCallback() {
                        @Override
                        public void done(com.parse.ParseException e) {
                            if (e == null) {
                                mProgressDialog.dismiss();
                                Toast.makeText(getActivity(), "Sucess saving", Toast.LENGTH_SHORT).show();
                                ImagesSingleton.getInstance().reset();
                                transferToRadar();
                            } else {
                                mProgressDialog.dismiss();
                                Toast.makeText(getActivity(), getResources().getString(R.string.error) + e.getLocalizedMessage(), Toast.LENGTH_SHORT).show();
                            }
                        }
                    });
                }
            }
        }
    });
}

I think it is quite clear in documentation how to delete an element(s) from an Array column in Parse. You simply have to send the list of the files you want to be removed from the Array like this:

offer.removeAll(ParseConstants.OFFER_PICTURES, listOfFilesToRemove);
offer.saveInBackground();

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM