cancel
Showing results for 
Show  only  | Search instead for 
Did you mean: 
Announcements
Musicians, convert your MuseScore files to PDF to play music on the go! Learn more here.

Discuss Dropbox Developer & API

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

what should be a file download path

what should be a file download path

kmsbs
Explorer | Level 4

what is the correct download path : 

 mDbxClient.files().download(Path =?);
 mDbxClient.files().download("https://www.dropbox.com/home/Apps/AndroidDbAppStorage")
.download(outputStream);

here its my 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("https://www.dropbox.com/home/Apps/AndroidDbAppStorage")
.download(outputStream);

// Tell android about the file
Intent intent = new Intent(mContext, LoginActivity.class);
mContext.startActivity(intent);

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();
} else {

}
}
}

 

13 Replies 13

kmsbs
Explorer | Level 4
what is the path pattern :

mDbxClient.files().download("https://www.dropbox.com/home/Apps/AndroidDbAppStorage/"+name)
.download(outputStream);

Greg-DB
Dropbox Staff

The path values you supply to the API should be paths relative to the root of the Dropbox account (or relative to the app folder root, if you're using an app with the app folder permission), not Dropbox web site URLs as you have here.

So, for example, to upload a file "myfile.txt" to your root, you would use "/myfile.txt". Or, to upload it into a subfolder "Documents", you would use "/Documents/myfile.txt".

You can also get the correct path values from Metadata.getPathLower, if/when you get the metadata for existing files elsewhere on the API:

https://dropbox.github.io/dropbox-sdk-java/api-docs/v3.0.x/com/dropbox/core/v2/files/Metadata.html#g...

kmsbs
Explorer | Level 4
here my path :

/Apps/AndroidDbAppStorage/"+name

it return empty file.

Greg-DB
Dropbox Staff
If the download call is returning successfully but is yielding a 0 byte file, it's likely because the file you have uploaded to Dropbox is 0 bytes long. You can check the Dropbox web site to confirm that.

If you don't expect to have a 0 byte file uploaded, you should check on where/how you're uploading it, and then upload the correct version.

kmsbs
Explorer | Level 4
File contain data and the size is in kb

Greg-DB
Dropbox Staff

If 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

kmsbs
Explorer | 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-DB
Dropbox Staff

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.

kmsbs
Explorer | Level 4

details_item-that file i want to importdetails_item-that file i want to import

Need more support?
Who's talking

Top contributors to this post

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