cancel
Showing results for 
Show  only  | Search instead for 
Did you mean: 
Announcements
Are you interested in learning how media industry leaders use Dropbox Replay? Register for our webinar here.

Dropbox API Support & Feedback

Find help with the Dropbox API from other developers.

cancel
Showing results for 
Show  only  | Search instead for 
Did you mean: 

[API] Can't download or overwrite a file after uploading it 1 time(android) (have to reload the app)

[API] Can't download or overwrite a file after uploading it 1 time(android) (have to reload the app)

AzErLoc
Explorer | Level 4

I'm not able to download or overwrite a file after uploading it 1 time. 

However when I kill the app and reload it it is ok, I can read it (download the string) but then I upload it and again I'm not able to interact with the file.
Here is the code of my function :


My functionMy functionTo get the string I tried using the download funtion of the api and downloading without the api and same result.

You can see the "Log" calls. At the first upload the 3 calls return their strings but the second time only the first one "First Phase" appear in the debuger.
It look like the async task doesn't start. I've also tried it without the upload function and all 3 calls appear in the debuger when I call it multiple time.
Sorry for my english and thank you for your help.

PS : I call the class with : new uploadFile(String aString, String fileName);

4 Replies 4

Greg-DB
Dropbox Staff

Can you share the code as text instead of a screenshot so we can try this? Thanks in advance! 

AzErLoc
Explorer | Level 4

 

package com.example.admin.prankclient;

import android.os.AsyncTask;
import android.util.Log;

import com.dropbox.core.DbxException;
import com.dropbox.core.DbxRequestConfig;
import com.dropbox.core.v2.DbxClientV2;
import com.dropbox.core.v2.files.FileMetadata;
import com.dropbox.core.v2.files.UploadErrorException;
import com.dropbox.core.v2.files.WriteMode;

import java.io.ByteArrayInputStream;
import java.io.FileNotFoundException;
import java.io.IOException;
import java.io.InputStream;
import java.nio.charset.Charset;

import static android.support.constraint.Constraints.TAG;

public class uploadFile {
    private static final String ACCESS_TOKEN = "xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx";
    private DbxRequestConfig config = null;
    DbxClientV2 client = null;
    private String command;
    private String foldername;
    uploadFile(String command, String foldername)
    {
        // Create Dropbox client
        config = new DbxRequestConfig("PrankClient");
        client = new DbxClientV2(config, ACCESS_TOKEN);
        this.command=command;
        this.foldername=foldername;
        Log.d(TAG,"------------------FIRST PHASE");
        new Uploading().execute();
        //Uploading run = new Uploading();
        //run.execute();

    }

    private class Uploading extends AsyncTask {


        @Override
        protected void onPostExecute(Object o) {
            Log.d(TAG,"------------------END");
            super.onPostExecute(o);
        }

        @Override
        protected Object doInBackground(Object[] objects) {
            Log.d(TAG,"------------------background");
            try {
                //String Dir = Environment.getExternalStorageDirectory().getAbsolutePath() + "/PrankClient";
                //InputStream in = new FileInputStream(Dir + "/Check.txt");
                InputStream in = new ByteArrayInputStream(command.getBytes(Charset.forName("UTF-8"))) ;

                FileMetadata metadata = client.files().uploadBuilder(foldername).withMode(WriteMode.OVERWRITE).uploadAndFinish(in);

                in.close();
            }
            catch (FileNotFoundException fne)
            {
                fne.printStackTrace();
            }
            catch (IOException ioe) {
                ioe.printStackTrace();
            } catch (UploadErrorException e) {
                e.printStackTrace();
            } catch (DbxException e) {
                e.printStackTrace();
            }

            return null;
        }
    }
}

Greg-DB
Dropbox Staff

Thanks! I just gave this code a try, hooking it up to a button in a sample project, and it worked fine for me when triggering it multiple times. I saw all three log statements each time.

I notice you did say that 'the second time only the first one "First Phase" appear', and that 'It look like the async task doesn't start', so it does sound like the issue you're seeing has to do with running the AsyncTask itself, before the Dropbox method is even called. (That is, since the Log call in doInBackground is before the Dropbox call.) I'm afraid I can't offer help with that though, since it has to do with Java/Android itself, and not the Dropbox call in particular.

AzErLoc
Explorer | Level 4

Thank you for your help. I updated my android studio and figured out what was causing this issue. It seems android studio wasn't able to process 2 async task at the same time.

Thank you again for your attention.

Need more support?
Who's talking

Top contributors to this post

  • User avatar
    AzErLoc Explorer | Level 4
  • User avatar
    Greg-DB Dropbox Staff
What do Dropbox user levels mean?