A bit of background: this app takes a picture and loads into the Blade Azure repository.
The image is saved in a file (internal storage) using getApplicationContext().getFilesDir();
To download, I need to call the uploadFromFile (..) function as follows: CloudBlockBlob.uploadFromFile(String path);
The Azure SDK uploadFromFile function is as follows:
public void uploadFromFile(final String path) throws StorageException, IOException { uploadFromFile(path, null , null , null ); } public void uploadFromFile(final String path, final AccessCondition accessCondition, BlobRequestOptions options, OperationContext opContext) throws StorageException, IOException { File file = new File(path); long fileLength = file.length(); InputStream inputStream = new BufferedInputStream(new FileInputStream(file)); this.upload(inputStream, fileLength, accessCondition, options, opContext); inputStream.close(); }
The problem is in the line long fileLength = file.length(); where the file length is 0.
I tested this against using Environment.getExternalStoragePublicDirectory(Environment.DIRECTORY_PICTURES); for the repository directory. It works.
I need to use internal storage and external storage, as this is necessary for this project.
EDIT: File mPhotoFile's documentation for the intent of my camera. It will contain a photo. mPhotoFileUri contains the URI for this file. Below is the code for using the path from the file.
File file = new File(mPhotoFile.getPath()); // value -> /data/user/0/com.example.devpactapp/files/JPEG_20160209_234929_1936823724.jpg boolean fileExists = file.exists(); // true long fileLength = file.length(); // length 0
Below is the code to get the file from the URI.
File file = new File(mPhotoFileUri.getPath()); // value -> /data/user/0/com.example.devpactapp/files/JPEG_20160209_235534_-1059496729.jpg boolean fileExists = file.exists(); // true long fileLength = file.length(); // length 0
I need to pass the path of this file to the uploadFromFile function.
The workaround mentioned in my "answer".