camera_windows save picture to different directory - flutter

I am using the flutter package camera_windows using the exact sample code listed here
camera_windows
It looks like by default it saves it to the "Pictures" directory in windows but I was wondering how do I save it to a different directory with a different filename also it looks like I cant pass a "path" to the call of the function for example
final XFile file = await CameraPlatform.instance.takePicture(_cameraId);
_showInSnackBar('Picture captured to: ${file.path}');

Related

How to get a list of all cached audio?

For example, my podcast app has a list of all downloaded podcast, how do I get a list of all LockCachingAudioSource that has been downloaded using request() method?
When you create your LockCachingAudioSource instances, you can choose the location where you want them to be saved. If you create a directory for that purpose, you can obtain a directory listing using Dart's file I/O API. The directory listing will also show partially downloaded files and other temporary files, which you want to ignore. These have extensions .mime and .part.
Having explained that, here is a solution. First, create your cache directory during app init:
final cacheDir = File('/your/choice/of/location');
...
await cacheDir.create(recursive: true);
Then for each audio source, create it like this:
import 'package:path/path.dart' as p;
...
source = LockCachingAudioSource(
uri,
cacheFile: File(p.joinAll([cacheDir, 'yourChoiceOfName.mp3'],
);
Now you can get a list of downloaded files at any time by listing the cacheDir and ignoring any temporary files:
final downloadedFiles = (await _getCacheDir()).list().where((f) =>
!['mime', 'part'].contains(f.path.replaceAll(RegExp(r'^.*\.'), '')));
If you need to turn these files back into the original URI, you could either create your own database to store which file is for which URI, or you choose the file name of each of your cache files by encoding the URI in base64 or something that's reversable, so given a file name, you can then decode it back into the original URI.

Flutter: How to get a File object from ImageProvider in Flutter?

How can I get a File from an ImageProvider?
ImageProvider imageProvider = NetworkImage(networkUrl);
File file = imageProvider ?
Although ImageProvider with NetworkImage renders the content of your network image URL, it doesn't have direct APIs or easy way for you to be able to convert it to a File object. With that said, you can still manually cache (or download) the image/s and get the download stream.
As far as I can understand your question, you are trying to access the network image URL as a File object. Instead of using ImageProvider, you can take a look at the flutter_cache_manager, which is a plugin used for downloading and caching files locally, and save it for later use.
Example Usage
Downloading network image file from URL
await DefaultCacheManager().downloadFile(url);
Retrieving File object from the cache dir
// Retrieving File object
var file = await DefaultCacheManager().getSingleFile(imageUrl);
// File object available for use
// Eg. Reading file as string
file.readAsStringSync(...);
Further reading
https://pub.dev/packages/flutter_cache_manager
https://pub.dev/packages/cached_network_image

How to get the uploaded file path in FilePicker

Currently we are able to drag and drop the folders and we are able to get all the files in the folder.
but we are not able to get the path of that files.
How can we get the file path of the files which are uploaded, so that we can maintain the same folder structure ?
In response from filepicker you receive list of objects.
Each object looks like this:
{
"url":"https://www.filepicker.io/api/file/0SIihoHPT8ORvwQ3EOPx",
"filename":"filepicker_test.png",
"mimetype":"image/png",
"size":4607,
"id":4,
"path":"/2/folder/filepicker_test.png",
"isWriteable":true
}
So you can restore directories structure using "path" key from filepicker answer.

Loading file using a path writen in edit box matlab

hello evryone
wanna load file from a specific path writen in an edit box named by 'Load_text', i got the path from the edit box using :
pth=get(handles.Load_text,'string');
then i used 'dir' as follow:
S=dir(fullfile([pth '*.bmp']));
that what cause me an errur . so any ideas ?
If you want to load a file then why you are using dir?
Since you have the file's name, then you can create the fullpath as you do with the fullpath method and check its existence with exists.
If the file exists, then you can load it with all available methods from MATLAB.
Keep in mind that this means that the file is in the same directory as your GUI files. If it is in another then you will have to add it in the fullpath call.
fullpath online doc: http://www.mathworks.com/help/matlab/ref/fullfile.html
exists online doc: http://www.mathworks.com/help/matlab/ref/exist.html

renameTo() not working on uploaded image : cos-MutipartRequest

I am trying to get an image uploaded by user, store it in a folder(for which I am providing absolute path), store the path in database(Relative path) abd later use the path from database todisplay the image.
I am using cos-MultipartRequest jar file for this.
I don't want to have spaces in the file name(Since the image with spaces in name is not displayed by <img>)
The code I have written is:
String pathUPLOAD="D:/AdvJava/proimp/WebContent/images/default";
String pathDB="images/default";
MultipartRequest m=new MultipartRequest(request,pathUPLOAD);
String file=m.getFilesystemName("file").replaceAll("\\s+",""); //to remove spaces
m.getFile("file").renameTo(new File(pathDB+file)); // to rename the uploaded file without whitespaces
//(tried this earlier) m.getFile("file").renameTo(new File(file));
the path I am inserting in DB is: pathDB+"/"+file
The upload works fine and later the images are also displayed for those which don't have spaces in name.
But for those having spaces, the path stored in DB is the way I want, but the image uploaded in the specified directory does not has any changes in its name and therefore the place where images are to be displayed shows a missing image.
Any suggestions?