【发布时间】:2018-01-17 14:32:59
【问题描述】:
我想上传简单的图片文件到谷歌云存储 当上传到根存储桶时,上传很顺利,但是当我尝试将图像上传到存储桶内的文件夹时,它失败了
以下是我这样做的代码
static Storage sStorage;
public static void uploadFileToServer(Context context, String filePath) {
Storage storage = getStorage(context);
StorageObject object = new StorageObject();
object.setBucket(BUCKET_NAME);
File sdCard = Environment.getExternalStorageDirectory();
File file = new File(sdCard + filePath);
try {
InputStream stream = new FileInputStream(file);
String contentType = URLConnection.guessContentTypeFromStream(stream);
InputStreamContent content = new InputStreamContent(contentType, stream);
Storage.Objects.Insert insert = storage.objects().insert(BUCKET_NAME, null, content);
insert.setName(file.getName());
insert.execute();
} catch (Exception e) {
e.printStackTrace();
}
}
我尝试将存储桶名称设置为 [PARENT_BUCKET]/[CHILD_FOLDER]
但它不起作用
【问题讨论】: