We’re Still Here to Help (Even Over the Holidays!) - find out more here.
Forum Discussion
kmsbs
8 years agoExplorer | Level 4
what should be a file download path
what is the correct download path :
mDbxClient.files().download(Path =?);
mDbxClient.files().download("https://www.dropbox.com/home/Apps/AndroidDbAppStorage") .downloa...
kmsbs
8 years agoExplorer | Level 4
File contain data and the size is in kb
Greg-DB
Dropbox Community Moderator
8 years agoIf something's not working as expected, I'll be happy to help, but I'll need some more information. Please reply with the following for the current issue:
- the version number of the SDK/library you are using
- the steps to reproduce the current issue, including relevant code snippet(s)
- the full text of the unexpected output
- a screenshot showing where you're checking that the file is not actually 0 bytes
- kmsbs8 years agoExplorer | Level 4
sdk version=
'com.dropbox.core:dropbox-core-sdk:3.0.8'code :
public class DownloadFileTask extends AsyncTask<FileMetadata, Void, File> {
private final Context mContext;
private final DbxClientV2 mDbxClient;
String name,path;
private File file;
DownloadFileTask(Context context, DbxClientV2 dbxClient, String path,String name) {
mContext = context;
mDbxClient = dbxClient;
this.path = path;
this.name=name;
}
@Override
protected File doInBackground(FileMetadata... params) {
try {
file=new File(path+name);
// Download the file.
OutputStream outputStream = new FileOutputStream(file);
mDbxClient.files().download("/Apps/AndroidDbAppStorage/"+name)
.download(outputStream);
return file;
} catch (DbxException | IOException e) {
}
return null;
}
@Override
protected void onPostExecute(File result) {
super.onPostExecute(result);
if (result.length()!=0) {
Toast.makeText(mContext, "File downloaded", Toast.LENGTH_SHORT).show();
Intent intent = new Intent(mContext, LoginActivity.class);
mContext.startActivity(intent);
} else {
}
}
}it return empty file
- Greg-DB8 years ago
Dropbox Community Moderator
I don't see anything obviously wrong in this code. It seems to be mostly copied/modified from the sample.
Can you share the other things I requested though? I.e., the output you're getting, and how you're checking the original file? I recall from your previous thread that you had an issue in your code that result in 0 byte files being uploaded to you account. It sounds like you perhaps didn't fix all of them.
- kmsbs8 years agoExplorer | Level 4
details_item-that file i want to import
- kmsbs8 years agoExplorer | Level 4output:
java.lang.NullPointerException: Attempt to invoke virtual method 'long java.io.File.length()' on a null object reference
at line :
protected void onPostExecute(File result) {
super.onPostExecute(result);
if (result.length()!=0) {
Toast.makeText(mContext, "File downloaded", Toast.LENGTH_SHORT).show();
Intent intent = new Intent(mContext, LoginActivity.class);
mContext.startActivity(intent);
} else {
}
}- Greg-DB8 years ago
Dropbox Community Moderator
Thanks for sharing that error output! That shows that you're getting a 'NullPointerException' for the 'File result' in your 'onPostExecute'. That is, the object itself is null, which is not the same as saying the downloaded file has zero length.
You'll need to investigate why your code isn't actually returning the 'file' object. I suspect it's because something is going wrong with the downloading or writing of the file, but, upon closer inspection of your code, it seems you're not seeing it because you're silently throwing away potential exceptions here:
} catch (DbxException | IOException e) { }You should add error handling there to take handle any issues that may arise (e.g., if you don't have permission to write to the local file path you specified, etc.).
About Discuss Dropbox Developer & API
Make connections with other developers
The Dropbox Community team is active from Monday to Friday. We try to respond to you as soon as we can, usually within 2 hours.
If you need more help you can view your support options (expected response time for an email or ticket is 24 hours), or contact us on X, Facebook or Instagram.
For more info on available support options for your Dropbox plan, see this article.
If you found the answer to your question in this Community thread, please 'like' the post to say thanks and to let us know it was useful!