user1906431
user1906431

Reputation: 49

Video uploading on parse server android

I am a beginner in android, can someone provide me working tutorial on uploading a video from the mobile video gallery and saving it on parse server? Thanks in advance ! `Intent intent = new Intent(Intent.ACTION_PICK, MediaStore.Video.Media.EXTERNAL_CONTENT_URI); intent.setType("video/*"); startActivityForResult(intent, 1);

    @Override
    public void onRequestPermissionsResult(int requestCode, @NonNull 
    String[] 
    permissions, @NonNull int[] grantResults) 
    {
    super.onRequestPermissionsResult(requestCode, permissions, 
    grantResults);

    if (requestCode == 1) 
    {
        if (grantResults.length > 0 && grantResults[0] == 
    PackageManager.PERMISSION_GRANTED) 
        {
            getPhoto();

        }
    }
   }


   @Override
   protected void onCreate(Bundle savedInstanceState) 
   {
    super.onCreate(savedInstanceState);
    setContentView(R.layout.activity_chat);

    if (checkSelfPermission(Manifest.permission.READ_EXTERNAL_STORAGE) != 
    PackageManager.PERMISSION_GRANTED) 
    {
        requestPermissions(new String[]
        {Manifest.permission.READ_EXTERNAL_STORAGE}, 1);
    } else {
        getPhoto();
    }

   }


    @Override
    protected void onActivityResult(int requestCode, int resultCode, Intent 
    data) 
   {
    super.onActivityResult(requestCode, resultCode, data);

    if(requestCode==1 && resultCode==ChatActivity.RESULT_OK && data!=null)
    {
        try
        {
            VideoView mVideo=(VideoView) findViewById(R.id.videoView);

            ByteArrayOutputStream stream = new ByteArrayOutputStream();


            byte[] byteArray =stream.toByteArray();
            ParseFile file = new ParseFile("resume.mp4", byteArray);

            ParseObject object = new ParseObject("Video");
            object.put("video",file);
            object.put("username", 
     ParseUser.getCurrentUser().getUsername());
            object.saveInBackground(new SaveCallback() 
            {
                @Override
                public void done(ParseException e) 
                {
                    if(e==null)
                    {
                        Toast.makeText(ChatActivity.this,"Vidoe 
    Saved",Toast.LENGTH_SHORT).show();
                    }
                    else
                    {
                        Toast.makeText(ChatActivity.this,"Vidoe not 
    Saved",Toast.LENGTH_SHORT).show();

                    }
                }
            });

        } 
        catch (Exception ex) 
        {
            ex.printStackTrace();
        }

    }`

I have given permission in manifest file for accessing the external data too !

Upvotes: 1

Views: 402

Answers (1)

förschter
förschter

Reputation: 860

You most likely want to use the ParseFile as described here docs.parseplatform.org for your video.

Upvotes: 0

Related Questions