Skip to content

Google-Developers-Group-IIIT-Lucknow/DevSphere-App-Android-Hard

Repository files navigation

🟢 Hard: Cloudinary Integration

Challenge Overview

In this challenge, you are tasked with completing a simple Android application that selects a file from the device and uploads it to Cloudinary. You are provided with a partially implemented MainActivity and must complete both the Cloudinary initialization and the file upload logic.

Your goal is to implement the missing logic to ensure the application correctly configures the Cloudinary MediaManager, captures the selected file URI, and successfully triggers the upload request.

Problem Description

You are given an Android project with a MainActivity.kt file containing a shell of the application logic.

You need to perform the following operations:

  1. Cloudinary Setup: Inside setupCloudinary(), initialize the MediaManager by providing your Cloudinary configuration parameters (i.e., cloud_name, api_key, and api_secret).
  2. Handle File Selection: Inside the filePickerLauncher callback, properly assign the selected uri to the fileUri class variable.
  3. Trigger File Upload: Implement the uploadFile() function using the Cloudinary MediaManager.get().upload(uri) API. Ensure you pass your actual upload preset instead of the default placeholder, and include the proper callbacks to handle upload states.

Expected Output

To successfully pass the assignment requirements, your implementation must satisfy the following checks:

  • The Cloudinary upload preset must not be left as "stub_preset", empty, or blank.
  • The application must gracefully handle valid and null URIs using the provided companion object validation checks (isValidUri).

How to Run

Run the unit tests:

./gradlew test

The unit tests are designed to fail initially. Your task is to modify MainActivity.kt until all tests in CloudinarySetupTest.kt and InputValidationTest.kt pass.

Important Implementation Notes

Cloudinary Initialization Ensure you initialize the MediaManager safely in setupCloudinary(). If the manager is already initialized, it throws an exception, which is why a try-catch block is provided. Replace the comments with actual initialization logic.

File Selection state When the filePickerLauncher successfully returns a file, assign the result to the globally declared fileUri variable so it is accessible within uploadFile().

Upload Implementation Details You must call MediaManager.get().upload(uri). Be sure to chain the required methods such as .unsigned("your_actual_upload_preset") (or .option("upload_preset", "your_actual_preset")), .callback(...), and finally call .dispatch().

Hints

  • Replace the "stub_preset" placeholder text with the actual upload preset created in your Cloudinary console.
  • In setupCloudinary(), use a HashMap of configuration values containing the keys "cloud_name", "api_key", and "api_secret" and pass it to MediaManager.init().
  • Use Android UI capabilities to update the interface based on the onStart, onProgress, onSuccess, and onError methods of the Cloudinary upload callback!
  • Remember: The code is intentionally left partially unimplemented. Your structural problem-solving and understanding of third-party SDK integration are key!

About

No description, website, or topics provided.

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

 
 
 

Contributors