使用Dropbox API、Android上传图像
捕获图像后,我不确定如何将位图作为文件上载。我通过以下方式获得位图:使用Dropbox API、Android上传图像,android,file,upload,dropbox,Android,File,Upload,Dropbox,捕获图像后,我不确定如何将位图作为文件上载。我通过以下方式获得位图: protected void onActivityResult(int requestCode, int resultCode, Intent data) { if(requestCode == CAM_REQUEST_CODE){ if(resultCode == RESULT_OK){ final Bitmap image = (
protected void onActivityResult(int requestCode, int resultCode, Intent data) {
if(requestCode == CAM_REQUEST_CODE){
if(resultCode == RESULT_OK){
final Bitmap image = (Bitmap)data.getExtras().get("data");
}
}
}
使用Dropbox API,通过以下方式上载文件:
File file = new File("working-draft.txt");
FileInputStream inputStream = new FileInputStream(file);
Entry response = mDBApi.putFile("/magnum-opus.txt", inputStream,
file.length(), null, null);
Log.i("DbExampleLog", "The uploaded file's rev is: " + response.rev);
非常感谢您在这方面提供的任何帮助。这里有一种方法可以帮助您:
- 通过tearrayoutputstream创建
- 调用
将JPEG/PNG字节写入outputstreamBitmap.compress()
- 从刚刚输出的字节数组创建一个
ByteArrayInputStream
- 将该输入流用于
方法putFile()
- 使用数组大小作为文件长度
不过,我会对记忆保持谨慎。是我,我试图找到一种方法来返回活动结果中的位图源,而不是实际的位图。请查看
putFile
方法采用InputStream
,因此如果可以直接将数据输入InputStream
,可以避免将其写入中间的文件。它还需要file.length(),不过。