cancel
Showing results for 
Show  only  | Search instead for 
Did you mean: 
Announcements
Want to learn some quick and useful tips to make your day easier? Check out how Calvin uses Replay to get feedback from other teams at Dropbox here.

Discuss Dropbox Developer & API

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

My uploaded files on Dropbox are 0 bytes/ empty.

My uploaded files on Dropbox are 0 bytes/ empty.

kmsbs
Explorer | Level 4
Go to solution

I have an app,In this app we are using dropbox v2 for upload or download  a file.

I uplaoded a file but it shown as a empty file and 0 byte.

1 Accepted Solution

Accepted Solutions

Greg-DB
Dropbox Staff
Go to solution

@kmsbs In your code, you're actually calling `uploadAndFinish` twice; once on its own, and then again inside your `Log.e` call. When you call the second time, the `inputStream` is consumed, so you end up uploading a zero byte file. Update your code to only do the upload once.

View solution in original post

7 Replies 7

Jane
Dropbox Staff
Go to solution
Hey kmsbs, thanks for getting in touch with us on the Dropbox Community! 
 
As I’d like to help you on the issue you’ve experienced as much as possible, can you clarify whether you’re uploading your file using the web Uploader, your mobile, through your desktop or if you’ve created your own app that’s uploading your files to the Dropbox folder? 
 
Once I have a bit more info, I’ll make sure to send you the most relevant next steps here. Thanks again & I’ll be awaiting your next post on this discussion! 

 


Jane
Community Moderator @ Dropbox
dropbox.com/support

 

Heart Did this post help you? If so please give it a Like below. 
:white_check_mark: Did this post fix your issue/answer your question? If so please press the 'Accept as Best Answer' button to help others find it.
:arrows_counterclockwise: Still stuck? Ask me a question! (
Questions asked in the community will likely receive an answer within 4 hours!)

kmsbs
Explorer | Level 4
Go to solution

this is my code :

 

 

public class UploadTask extends AsyncTask {
private DbxClientV2 dbxClient;
private File file;
@SuppressLint("StaticFieldLeak")
private Context context;
ProgressDialog dialog;

UploadTask(DbxClientV2 dbxClient, File file, Context context) {
this.dbxClient = dbxClient;
this.file = file;
this.context = context;
}

@Override
protected Object doInBackground(Object[] params) {
try {
// Log.e("async read",ReadFile(file));
InputStream inputStream = new FileInputStream(file);
dbxClient.files().uploadBuilder("/" +file.getName()) //Path in the user's Dropbox to save the file.
.withMode(WriteMode.OVERWRITE) //always overwrite existing file
.uploadAndFinish(inputStream);
Log.e("Upoad", "" + dbxClient.files().uploadBuilder("/" + file.getName()) //Path in the user's Dropbox to save the file.
.withMode(WriteMode.OVERWRITE) //always overwrite existing file
.uploadAndFinish(inputStream));
} catch (DbxException e) {
e.printStackTrace();

} catch (IOException e) {
e.printStackTrace();
}
return null;

}

@Override
protected void onPostExecute(Object o) {
super.onPostExecute(o);
DownloadActivity.dialog.dismiss();
Toast.makeText(context, "File uploaded successfully", Toast.LENGTH_SHORT).show();
Intent intent = new Intent(context, LoginActivity.class);
intent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
context.startActivity(intent);

}

public static String ReadFile(File file){
String line = null;

try {
FileInputStream fileInputStream = new FileInputStream (file);
InputStreamReader inputStreamReader = new InputStreamReader(fileInputStream);
BufferedReader bufferedReader = new BufferedReader(inputStreamReader);
StringBuilder stringBuilder = new StringBuilder();

while ( (line = bufferedReader.readLine()) != null )
{
stringBuilder.append(line + System.getProperty("line.separator"));
}
fileInputStream.close();
line = stringBuilder.toString();

bufferedReader.close();
}
catch(FileNotFoundException ex) {
Log.d("FileNotFoundException", ex.getMessage());
}
catch(IOException ex) {
Log.d("IOException", ex.getMessage());
}
return line;
}
}

kmsbs
Explorer | Level 4
Go to solution

File data : 

 

[{"Working-hours":[{"User-id":"1","User-name":"user1","Client-id":"1","Client-name":"test1","Project-id":"1","Project-name":"name1","Job-id":"1","Job-name":"job1","Start-hour":"7","End-hour":"18","Work-date":"30-04-2018","Total-Working-hours":"8-hours","Edit-time":"19.00-30-04-2018","material-name":"material1","material-date":"30-04-2018","Notes":"note1"},{"User-id":"2","User-name":"user2","Client-id":"2","Client-name":"test2","Project-id":"2","Project-name":"name2","Job-id":"2","Job-name":"job2","Start-hour":"7","End-hour":"18","Work-date":"30-04-2018","Total-Working-hours":"8-hours","Edit-time":"19.00-30-04-2018","material-name":"material2","material-date":"30-04-2018","Notes":"note2"},{"User-id":"3","User-name":"user3","Client-id":"3","Client-name":"test3","Project-id":"3","Project-name":"name3","Job-id":"3","Job-name":"job3","Start-hour":"7","End-hour":"18","Work-date":"30-04-2018","Total-Working-hours":"8-hours","Edit-time":"19.00-30-04-2018","material-name":"material3","material-date":"30-04-2018","Notes":"note3"}],"Used-materials":[{"User-id":"1","User-name":"user1","Client-id":"1","Client-name":"test1","Project-id":"1","Project-name":"name1","Material-id":"1","Material-name":"material1","Date":"04-05-2018"},{"User-id":"2","User-name":"user2","Client-id":"1","Client-name":"test2","Project-id":"2","Project-name":"name2","Material-id":"1","Material-name":"material2","Date":"04-05-2018"},{"User-id":"3","User-name":"user3","Client-id":"3","Client-name":"test3","Project-id":"3","Project-name":"name3","Material-id":"3","Material-name":"material3","Date":"04-05-2018"}]}]

Jane
Dropbox Staff
Go to solution

Hey kmsbs, I've moved your thread to the API section, as this will need to be reviewed by my colleagues here. 

 

Thanks for reaching out to us & enjoy the rest of your day! 

 


Jane
Community Moderator @ Dropbox
dropbox.com/support

 

Heart Did this post help you? If so please give it a Like below. 
:white_check_mark: Did this post fix your issue/answer your question? If so please press the 'Accept as Best Answer' button to help others find it.
:arrows_counterclockwise: Still stuck? Ask me a question! (
Questions asked in the community will likely receive an answer within 4 hours!)

kmsbs
Explorer | Level 4
Go to solution
hello sir,
any solution

Greg-DB
Dropbox Staff
Go to solution

@kmsbs In your code, you're actually calling `uploadAndFinish` twice; once on its own, and then again inside your `Log.e` call. When you call the second time, the `inputStream` is consumed, so you end up uploading a zero byte file. Update your code to only do the upload once.

kmsbs
Explorer | Level 4
Go to solution
thanks it work fine
Need more support?
Who's talking

Top contributors to this post

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