PHPFixing
  • Privacy Policy
  • TOS
  • Ask Question
  • Contact Us
  • Home
  • PHP
  • Programming
  • SQL Injection
  • Web3.0

Friday, July 29, 2022

[FIXED] How to upload an image in parse server using parse api in android

 July 29, 2022     android, android-drawable, image, parse-platform     No comments   

Issue

I want to upload an image in parse cloud server in android. But I am unable to do so.

I have tried the following code:

Drawable drawable = getResources().getDrawable(R.drawable.profilepic) ;
Bitmap bitmap = (Bitmap)(Bitmap)drawable()
ByteArrayOutputStream stream = new ByteArrayOutputStream();
bitmap.compress(Bitmap.CompressFormat.PNG, 100, stream);
byte[] data = stream.toByteArray();                

ParseFile imageFile = new ParseFile("image.png", data);
imageFile.saveInBackground();

Please let me know how can I do it.


Solution

Save ParseObject in the background

// ParseObject
  ParseObject pObject = new ParseObject("ExampleObject");
  pObject.put("myNumber", number);
  pObject.put("myString", name);
  pObject.saveInBackground(); // asynchronous, no callback

Save in the background with callback

pObject.saveInBackground(new SaveCallback () {
   @Override
   public void done(ParseException ex) {
    if (ex == null) {
        isSaved = true;
    } else {
        // Failed
        isSaved = false;
    }
  }
});

Variations of the save...() method include the following:

    saveAllinBackground() saves a ParseObject with or without a callback.
    saveAll(List<ParseObject> objects) saves a list of ParseObjects.
    saveAllinBackground(List<ParseObject> objects) saves a list of ParseObjects in the 
    background.
    saveEventually() lets you save a data object to the server at some point in the future; use 
    this method if the Parse cloud is not currently accessible.

Once a ParseObject has been successfully saved on the Cloud, it is assigned a unique Object-ID. This Object-ID is very important as it uniquely identifies that ParseObject instance. You would use the Object-ID, for example, to determine if the object was successfully saved on the cloud, for retrieving and refreshing a given Parse object instance, and for deleting a particular ParseObject.

I hope you will solve your problem..



Answered By - Make it Simple
Answer Checked By - Robin (PHPFixing Admin)
  • Share This:  
  •  Facebook
  •  Twitter
  •  Stumble
  •  Digg
Newer Post Older Post Home

0 Comments:

Post a Comment

Note: Only a member of this blog may post a comment.

Total Pageviews

Featured Post

Why Learn PHP Programming

Why Learn PHP Programming A widely-used open source scripting language PHP is one of the most popular programming languages in the world. It...

Subscribe To

Posts
Atom
Posts
Comments
Atom
Comments

Copyright © PHPFixing