I know how to upload a file to google drive, using an asynchronous task, able to cancel the async task. But, how to stop the uploading process.
insert = service.files().insert(image, image_content);
insert.execute();
please refer to below link, By Closing FileinputStream you can stop uploading process.
Android How to stop/kill/cancel Media Upload or Download
java.io.File fileContent = new java.io.File(imageUrl);
fileStream = new FileInputStream(fileContent);
InputStreamContent mediaContent = new InputStreamContent("image/jpeg", new BufferedInputStream(fileStream));
insert = service.files().insert(image, mediaContent);
insert.execute();
Related
We are trying to make it possible for users to select entire folders to upload them to our back end. This is no problem on Android and iOS, where I can use getDirectoryPath() from FilePicker, and then get all the files using Directory(path).listSync(recursive: true).
The issue is that this isn't available on web, and while i can exchange dart:io for universal_io, that doesn't help with getDirectoryPath().
Is there any other approach that I can use here? The end goal is to upload the selected folder to Google Cloud Storage, so one Idea that I have is to bypass Flutter entirely, but I haven't figured out a way to do that yet. Any ideas?
There is File System Access API and showDirectoryPicker, which would be the way to go, but it is not supported by all browsers.
One option would be to allow a user to pick multiple files and upload bytes. Not the same thing, but in some cases would be sufficient. Something like this:
final result = await FilePicker.platform.pickFiles(allowMultiple: false);
if (result != null && result.files.isNotEmpty) {
final fileBytes = result.files.first.bytes;
final fileName = result.files.first.name;
// TODO upload file
}
Use a JavaScript library: You can use a JavaScript library such as file-uploader or dropzone.js to handle file uploads in your web application. These libraries provide a file explorer interface for the user to select and upload files, and can be integrated with Flutter using dart:js and package:js
I am new to path_provider. I am making a music app and want to download an mp3 file but I don't know which is the right way to download the file within the application.
I want to store the file with application storage so users can not access it directly.
so where i can store it?
final dir = await getApplicationDocumentsDirectory();
final dir2 = await getApplicationSupportDirectory();
print(dir.path);
print(dir2.path);
<---------- Output of path ----------->
/data/user/0/com.oraysa/app_flutter.
/data/user/0/com.oraysa/files
together with this one more question is how can I access downloaded files ( get info of all downloaded files). how can I find the same file so next time I don't have to download it again, instead just directly load it from storage?
I'm looking into a way to download a file from a url and immediately stream it (upload) it to another url (location). I don't want to dump it into disk or download the whole file in memory.
I'm new to Spring Reactive API. I came up with something like this in Kotlin:
val buff = WebClient.create("downloadUrl").get().retrieve().bodyToFlux(DataBuffer::class.java)
WebClient.create("uploadUrl").post().body(buff)
body above is org.springframework.web.reactive.function.client.body
But I'm not sure if I'm even on the right path. What is the right way of doing it?
We have a flutter application where we want to use map functionality in offline mode.
Mapbox provides functionality in the flutter to use offline maps but .db file which contains offline data needs to be saved in the project at build time.
How to achieve the same at runtime?
also open to suggestions to use any other map service providers that works in both online and offline mode.
If you want to store a file on the device please read the official Flutter documentation about Reading and Writing Files
Essentially you need to add path_provider package to your project in order to retrieve the standard cache folder for every device and then simply save you file in it.
This is a my application similar behaviour code
//Get an available temporary dir on device using path_provider package
final Directory tempDir = await getTemporaryDirectory();
//Create a path with file name
final String tempPath = tempDir.path + '/' + 'yourFileName.db';
//Write file on device disk
final File file = File(tempPath);
await writeAsBytesSync(fileContent); //If it is a string use writeAsStringAsync
print('File written on disk');
Then using the file path you can simply read it from disk using readAsByteAsync method.
Remember that in the sample we are using getTemporaryDirectory() and as the documentation tell us
Path to the temporary directory on the device that is not backed up and is suitable for storing caches of downloaded files.
Files in this directory may be cleared at any time.
I would recommend to check out this issue on the github page of the flutter-mapbox-gl repository:
https://github.com/tobrun/flutter-mapbox-gl/issues/88
See the comment of vinceKruger:
https://github.com/tobrun/flutter-mapbox-gl/issues/88#issuecomment-559380534
It is not an official way, but seems to work!
I'm building an app that logs data and saves it on your phone.
Where is the correct place to save it, if i want to be able to easily transfer it off my phone later on?
According to the Flutter docs i would normally do something like this:
final directory = await getApplicationDocumentsDirectory();
return directory.path;
but this returns the path of
/data/user/0/com.myApp.myApp_app/app_flutter
Which i believe can only be accessed if you are root or the app that created the file.
So where and how do i save my file so that i can find it later in a file browser
**EDIT:**Here is what i ended up doing
create file like so File file = new File('/storage/emulated/0/Download/data.txt');
add <uses-permission android:name="android.permission.WRITE_EXTERNAL_STORAGE" /> to your AndroidManifest.xml
Once the app is installed go into app info and toggle on permission for storage. I originally thought this would have been done automatically but guess not.
You were doing this right, but something was missing. I'm writing it out for you. It may help you. Let me know if that works.
What you can do is this :
String directory = (await getApplicationDocumentsDirectory()).path;
File file = new File('$directory/$your_file_name_in_your_local_device');
await file.writeAsBytes(dataInBytes);
print(file.path);
In order to get the data in bytes, please do this:
var dataInBytes = await request.bodyBytes;
Happy coding :)