title: Android: How to upload a file to OneDrive?
body: <p>Iam trying to upload a file using the OneDrive Saver sample app. Instead of creating a text file, I would like to select a file from the gallery and then upload it to OneDrive. I have edited the sample app but the file cannot be uploaded. I don't have any errors. </p>
  
  <p>Sample app available on GitHub (<a href="https://github.com/OneDrive/onedrive-picker-android/tree/master/SaverSample" rel="nofollow">https://github.com/OneDrive/onedrive-picker-android/tree/master/SaverSample</a>).</p>
  
  <pre><code>package com.example.onedrivesdk.saversample;
  
  import java.io.*;
  import android.accounts.AccountManager;
  import android.app.Activity;
  import android.content.ContentResolver;
  import android.content.Intent;
  import android.database.Cursor;
  import android.graphics.Bitmap;
  import android.graphics.BitmapFactory;
  import android.net.Uri;
  import android.os.*;
  import android.provider.MediaStore;
  import android.view.View;
  import android.view.View.OnClickListener;
  import android.widget.*;
  import com.microsoft.onedrivesdk.saver.*;
  
  public class SaverMain extends Activity {
  
      private static final int DEFAULT_FILE_SIZE_KB = 100;
      static final int                RESULT_STORE_FILE = 4;
      private static Uri              mFileUri;
      private static final String ONEDRIVE_APP_ID = "4813EF88";
  
  
      private final OnClickListener mStartPickingListener = new OnClickListener() {
          @Override
          public void onClick(final View v) {
  
              final Intent galleryIntent = new Intent(Intent.ACTION_PICK);
              galleryIntent.setType("*/*");
              startActivityForResult(galleryIntent, RESULT_STORE_FILE);
  
          }
      };
  
  
      private ISaver mSaver;
  
      @Override
      protected void onCreate(final Bundle savedInstanceState) {
          super.onCreate(savedInstanceState);
          setContentView(R.layout.activity_saver_main);
  
          // Create the picker instance
          mSaver = Saver.createSaver(ONEDRIVE_APP_ID);
  
          // Add the start saving listener
          findViewById(R.id.startSaverButton).setOnClickListener(mStartPickingListener);
      }
  
      @Override
      protected void onActivityResult(final int requestCode, final int resultCode, final Intent data) {
  
          try {
              mSaver.handleSave(requestCode, resultCode, data);
  
          } catch (final SaverException e) {
  
          }
          switch (requestCode) 
          {
  
              case RESULT_STORE_FILE:
  
                  mFileUri = data.getData();
                  saveFileToDrive();
                  break;
  
          }
  
  
      }
  
  
      private void saveFileToDrive() 
      {
          Thread t = new Thread(new Runnable() 
          {
              @Override
              public void run() 
              {
                  try 
                  {
                      // Create URI from real path
                      String path;
                      path = getPathFromUri(mFileUri);
                      mFileUri = Uri.fromFile(new java.io.File(path));
  
                      ContentResolver cR = SaverMain.this.getContentResolver();
  
                      // File's binary content
                      java.io.File fileContent = new java.io.File(mFileUri.getPath());
                      View v = null;
                      final Activity activity = (Activity) v.getContext();
                      mSaver.startSaving(activity, path, Uri.parse(mFileUri.toString()));
  
  
                  } catch (Exception e) {
  
                  } 
              }
          });
          t.start();
      }
  
      public String getPathFromUri(Uri uri) 
      {
            String[] projection = { MediaStore.Images.Media.DATA };
            Cursor cursor = getContentResolver().query(uri, projection, null, null, null);
            int column_index = cursor
                    .getColumnIndexOrThrow(MediaStore.Images.Media.DATA);
            cursor.moveToFirst();
            return cursor.getString(column_index);
      }
  
  
  }
  </code></pre>