我正在使用以下代码段使用JSON API将图像上传到Android的Google云端存储。虽然我在上传之前测试了文件大小,但不是零,上传后文件大小变为零。
InputStream is = getContentResolver().openInputStream(imageUri); //imageUri is obtained after the image is chosen
Storage storage = getStorage();
//The below three lines are a test to get the file size
Bitmap selectedImage1 = BitmapFactory.decodeStream(is);
byte[] imageByte = Utilities.getBytesFromBitmap(selectedImage1);
int size = imageByte.length;
StorageObject object = new StorageObject().setName("myobject")
.setContentDisposition("attachment");
String contentType = "image/jpeg";
InputStreamContent content = new InputStreamContent(contentType, is);
content.setRetrySupported(true);
Storage.Objects.Insert insert = storage.objects().insert("mybucket.appspot.com", object, content); //bucketname changed
insert.execute();
我已经看了一下stackoverflow中的大多数相关问题,但还是找不到解决方案。