Back

[SOLVED]Storage API. Android SDK(java)

  • 0
  • Android
  • Databases
asapsonter
28 Mar, 2023, 03:05

I created a bucket from console and connected my project to appwrite SDK etc. Now I am trying to send file(s) from mobile External Dir to storage.

TypeScript
// push to clould func

public void cloudStorage() {
String endPoint = "*****"
String setProject = "*****"
String apiKey = "*****"
String bucketID = "*****"

  Client client = new Client(requireActivity());
        client.setEndpoint(endpoint);
        client.setProject(project);
        client.setSelfSigned(true);
File file = new File(Objects.requireNonNull(requireContext().getExternalFilesDir(null).getParent())); //externaldir path

 Storage storage = new Storage(client);

        storage.createFile(
                bucketID,
                file,
                InputFile.Companion.fromPath("FILE.xls"),
                new CoroutineCallback<>(result, error) ->{
            if (error != null) {
                error.printStackTrace();
                return;

            }
            Log.d("Appwrite", result.toString());
        }

}

So when trying to use CoroutineCallback can =not resolve symbool 'result' & 'error' which are supposed to be the object and error handler. after a deep research, I noticed CoroutineCallback is a class in appwrite SDK for kotlin .

Pls help me know how i can handle this task with android JAVA SDK.

TL;DR
The user was having an issue with the syntax of the `CoroutineCallback` in the Storage API of the Android SDK (Java). They were getting an error "cannot resolve symbol 'result' & 'error'", which was due to a small mistake in their code syntax. The solution to the issue was to add missing parentheses around the `result,error` parameters in the `CoroutineCallback` callback. Here's the modified code: ```java storage.createFile( bucketID, file, InputFile.Companion.fromPath("FILE.xls"), new CoroutineCallback<>((result, error) -> { if (error !=
safwan
28 Mar, 2023, 03:23

CoroutineCallback can be used with the Java SDK for appwrite as well.

To address your error - can =not resolve symbool 'result' & 'error' - it looks a small mistake in your syntax.

Your code:

TypeScript
storage.createFile(
    bucketID,
    file,
    InputFile.Companion.fromPath("FILE.xls"),
    new CoroutineCallback<>(result, error) ->{
     if (error != null) {
         error.printStackTrace();
         return;

      }
      Log.d("Appwrite", result.toString());
}

Fixed code:

TypeScript
storage.createFile(
    bucketID,
    file,
    InputFile.Companion.fromPath("FILE.xls"),
    new CoroutineCallback<>((result, error) -> {
        if (error != null) {
            error.printStackTrace();
            return;
        }

        Log.d("Appwrite", result.toString());
    })
);
safwan
28 Mar, 2023, 03:25

You seem to have missed a couple of parentheses. Especially the ones for the CoroutineCallback. Instead of CoroutineCallback<>(result, error) -> {}, you need to do CoroutineCallback<>((result, error) -> {})

Hope this makes sense.

safwan
28 Mar, 2023, 03:25

Feel free to ask any questions if this doesn't work

asapsonter
28 Mar, 2023, 06:38

Thanks that worked. I was careless with the syntax. I am new to this server. How can i close this question or mark Solved.

safwan
28 Mar, 2023, 06:41

Not an issue, happens to the best of us!

safwan
28 Mar, 2023, 06:42

To mark the question as solved, just edit the post title to [SOLVED] Storage API. Android SDK(java)

asapsonter
28 Mar, 2023, 06:43

[SOLVED]Storage API. Android SDK(java)

Reply

Reply to this thread by joining our Discord

Reply on Discord

Need support?

Join our Discord

Get community support by joining our Discord server.

Join Discord

Get premium support

Join Appwrite Pro and get email support from our team.

Learn more