我尝试使用此代码在 android 的 GCS 上上传文件。此代码运行完美,并在存储桶上上传文件。但是现在我想使用暂停/恢复功能在后台(从服务)上传文件,当互联网连接消失时将暂停,当互联网连接可用时恢复。我在互联网上搜索了很多,但没有找到任何完美的解决方案。
CloudStorage.uploadFile("upload-recording", "/storage/sdcard0/Download/images.jpg",this,file);
public static void uploadFile(String bucketName, String filePath,Context context,File file_use)
throws Exception {
this_context = context;
this_file = file_use;
Storage storage = getStorage();
StorageObject object = new StorageObject();
object.setBucket(bucketName);
File file = new File(filePath);
InputStream stream = new FileInputStream(file);
try {
String contentType = URLConnection
.guessContentTypeFromStream(stream);
InputStreamContent content = new InputStreamContent(contentType,
stream);
Storage.Objects.Insert insert = storage.objects().insert(
bucketName, null, content);
insert.setName(file.getName());
insert.execute();
} finally {
stream.close();
}
}