Note that there are some explanatory texts on larger screens.

plurals
  1. POUpload file to Drop box from android application
    text
    copied!<p>I am trying to upload a text file to dropbox. The authentication works fine, but when it tries to upload the file, the application crashes. here is my code</p> <pre><code>public class Dropboxupload extends Activity { final static private String APP_KEY = "KEY"; final static private String APP_SECRET = "SECRET"; final static private AccessType ACCESS_TYPE = AccessType.APP_FOLDER; private DropboxAPI&lt;AndroidAuthSession&gt; mDBApi; @Override protected void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); setContentView(R.layout.activity_main); AppKeyPair appKeys = new AppKeyPair(APP_KEY, APP_SECRET); AndroidAuthSession session = new AndroidAuthSession(appKeys, ACCESS_TYPE); mDBApi = new DropboxAPI&lt;AndroidAuthSession&gt;(session); mDBApi.getSession().startAuthentication(Dropboxupload.this); } @Override public boolean onCreateOptionsMenu(Menu menu) { // Inflate the menu; this adds items to the action bar if it is present. getMenuInflater().inflate(R.menu.dropboxupload, menu); return true; } /* Called when the application resumes */ @Override protected void onResume() { super.onResume(); if (mDBApi.getSession().authenticationSuccessful()) { try { // Required to complete auth, sets the access token on the session mDBApi.getSession().finishAuthentication(); AccessTokenPair tokens = mDBApi.getSession().getAccessTokenPair(); } catch (IllegalStateException e) { Log.i("DbAuthLog", "Error authenticating", e); } String filePath = getApplicationContext().getFilesDir().getPath().toString() + "/magnus-opus.txt"; File file = new File(filePath); try { file.createNewFile(); } catch (IOException e2) { // TODO Auto-generated catch block e2.printStackTrace(); } FileInputStream inputStream = null; try { inputStream = new FileInputStream(file); } catch (FileNotFoundException e1) { // TODO Auto-generated catch block e1.printStackTrace(); } try { com.dropbox.client2.DropboxAPI.Entry response = mDBApi.putFile("/magnum-opus.txt", inputStream, file.length(), null, null); Log.i("DbExampleLog", "The uploaded file's rev is: " + response.rev); } catch (DropboxException e) { // TODO Auto-generated catch block e.printStackTrace(); } } } private void writeToFile(String data,String filepath, String filename) { try { OutputStreamWriter outputStreamWriter = new OutputStreamWriter(openFileOutput(filepath, Context.MODE_PRIVATE)); outputStreamWriter.write(data); outputStreamWriter.close(); } catch (IOException e) { Log.e("Exception", "File write failed: " + e.toString()); } } } </code></pre> <p>I am also posting the error log here, any help would be appreciated.</p> <pre><code> 11-21 18:04:20.094: W/System.err(16838): DropboxServerException (nginx): 403 Forbidden (Forbidden) 11-21 18:04:20.094: W/System.err(16838): at com.dropbox.client2.RESTUtility.parseAsJSON(RESTUtility.java:263) 11-21 18:04:20.094: W/System.err(16838): at com.dropbox.client2.RESTUtility.execute(RESTUtility.java:411) 11-21 18:04:20.094: W/System.err(16838): at com.dropbox.client2.DropboxAPI$BasicUploadRequest.upload(DropboxAPI.java:1080) 11-21 18:04:20.104: W/System.err(16838): at com.dropbox.client2.DropboxAPI.putFile(DropboxAPI.java:1421) 11-21 18:04:20.104: W/System.err(16838): at com.example.screenwritter.Dropboxupload$1.run(Dropboxupload.java:85) 11-21 18:04:20.104: W/System.err(16838): at java.lang.Thread.run(Thread.java:856) 11-21 18:04:43.506: W/IdleConnectionHandler(16838): Removing a connection that never existed! </code></pre>
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload