Expo SDK Version: 36.0.0
Platform: iOS Simulator
I need to copy a .db file from assets to the FileSystem.documentDirectory but I get an error. Here's the code I'm trying:
await FileSystem.downloadAsync(
Asset.fromModule(require('../assets/databases/data.db')).uri,
`${FileSystem.documentDirectory}SQLite/data.db`
);
Here's the error I get:
Unable to resolve module "../assets/databases/data.db"
None of these files exist:
* assets/databases/data.db(.native|.ios.expo.ts|.native.expo.tx|.expo.ts|.ios.expo.tsx|.native.expo.tsx|.expo.tsx|.ios.expo.js|.native.expo.js|.expo.js|.ios.expo.jsx|.native.expo.jsx|.expo.jsx|.ios.ts|.native.ts|.ts|.ios.tsx|.native.tsx|.tsx|.ios.js|.native.js|.js|.ios.jsx|.native.jsx|.jsx|.ios.json|.native.json|.json|.ios.wasm|.native.wasm|.wasm)
How do i copy a .db file from assets to the FileSystem.documentDirectory folder? I just need to copy a .db file from assets to the FileSystem.documentDirectory folder, but this error makes it look like Asset.fromModule only allows image files.
If I use the exact same code but replace the .db file with a .png file, it works.
Expo SDK Version: 36.0.0
Platform: android expo client sdk-qr code
i am also need this db file and i dont understand how to get it ..
my code here just give me the path ..but no have path like that , i just want to see my db file and i want to save this file in my desktop . how can i do that ?
const { uri } = await FileSystem.getInfoAsync(
`${FileSystem.documentDirectory}SQLite/${'places.db'}`
)
console.log("THIS IS PATH OF THE DB",uri)
I found the answer from a combination of expo forum posts, primarily this one: https://forums.expo.io/t/unable-to-load-obj-file-using-require/15794/3
The problem is that by default, the expo Assets api doesn't recognize .db files, so you have to create a file in the root of your project called metro.config.js and then add the following code to the file:
module.exports = {
resolver: {
assetExts: ["db", "ttf", "png"]
}
};
After that, you can then do this and it will work:
await FileSystem.downloadAsync(
Asset.fromModule(require('../assets/databases/data.db')).uri,
`${FileSystem.documentDirectory}SQLite/data.db`
);
Related
I am trying to read a file in a test/debug UWP application that is being deployed to Hololens. I can put the file on the device with the device portal, but am unable to find the correct path to open the file.
I am using the MSFT BasicXrApp_uwp example as a basis, and have included FileUtility which has a FindFileInAppFolder function. This is consistently failing to find the file, with the error:
"The file should be embeded in app folder in debug build.",
after letting me know the app folder is:
C:\Data\Users\DefaultAccount\AppData\Local\DevelopmentFiles\364f83f4-6e13-42e4-8253-71dd3040951cVS.Debug_ARM.mikeh\
The part 364f83f4-6e13-42e4-8253-71dd3040951cVS is recognisable in the device portal as the User Folders/LocalAppData folder, but the Debug_ARM.mikeh part is not visible on the portal.
I am using C++ and trying to do the file reading in a static, non uwp library if possible (pointing that out so I don't get suggestions to use UWP async stuff, if that is possible).
So, how do I embed my file in the app folder, or how do I place the file so I can read it?
This is because the folder path which FindFileInAppFolder method returns is the InstalledLocation of the current package, but what you checked in the device portal is LocalFolder/LocalCacheFolder, for more information about what different between them please see: File access permissions.
how do I embed my file in the app folder, or how do I place the file so I can read it?
You can place your file in the LocalState folder by Device Portal and get this folder path through ApplicationData.LocalFolder Property, the path should be like: C:\Data\Users\DefaultAccount\AppData\Local\Packages\364f83f4-6e13-42e4-8253-71dd3040951c\LocalState. For how to access the files via C++ you can use for example File access sample
I'm using an answer here as there's more room than a comment.
I found a few extra things useful. I added in the cppWinRT nuget package to my application.
I did need to use the "async stuff", for example:
using namespace winrt;
using namespace Windows::Foundation;
using namespace Windows::Storage;
StorageFolder storageFolder= KnownFolders::GetFolderForUserAsync(nullptr, KnownFolderId::PicturesLibrary).get();
This let me find a file I'd uploaded ot the Pictures Library. But I couldn't open it after passing the path to my existing library:
const auto sampleFile = storageFolder.GetFileAsync(fileName).get();
std::wstring path = sampleFile.Path();
MyLibraryCall(to_string(path));
MyLibraryCall would try and open an ifstream, and even using std::ifstream::in would fail.
So I copied the file to the temp directory, where I could open it and process it.
This is pretty hacky but it did what I needed, which is let me load an .obj file that was rejected by the 3D parts viewer.
The loop over all filenames is because storageFolder.GetFileAsync(fileName).get() throws an exception if it fails, which for me I could not catch properly.
StorageFolder tempFolder = Windows::Storage::ApplicationData::Current().TemporaryFolder();
std::wstring path;
auto files = tempFolder.GetFilesAsync().get();
for (auto file : files)
{
if (file.Name() == fileName) {
path = file.Path();
break;
}
}
if (!path.size()) {
// hasn't been copied into temp
StorageFile movedFile = sampleFile.CopyAsync(tempFolder).get();
path = movedFile.Path();
}
MyLibraryCall(to_string(path));
Anyway- not the greatest but that will hopefully help someone else looking for a quick and dirty way to process a file on a hololens/UWP app.
I would like to use a custom font in my shiny app (on plots) on shinyapps.io. I have my Roboto-Regular.ttf in the ./www/ directory. And this is the upper portion of my app.R file:
dir.create('~/.fonts')
system("chmod +x ./www/Roboto-Regular.ttf")
system("cp ./www/Roboto-Regular.ttf ~/.fonts/")
system('fc-cache -f -v ~/.fonts/')
system('fc-match Roboto')
library(ggplot2)
library(shiny)
library(shinythemes)
library(extrafont)
font_import(pattern="Roboto",prompt=FALSE)
loadfonts()
print(fonts())
Upon deploying the app, I end up with an error that looks like this:
Registering fonts with R
Scanning ttf files in /usr/share/fonts/, ~/.fonts/ ...
Extracting .afm files from .ttf files...
/home/shiny/.fonts/Roboto-Regular.ttfWarning in gzfile(dest, "w") :
cannot open compressed file '/opt/R/3.5.1/lib/R/library/extrafontdb/metrics/Roboto-Regular.afm.gz', probable reason 'Permission denied'
Error in value[[3L]](cond) : cannot open the connection
Calls: local ... tryCatch -> tryCatchList -> tryCatchOne -> <Anonymous>
Execution halted
Does anyone see what might be wrong?
After a bit of struggle I found an even simpler solution that works on shinyapps.io:
Here we go:
Place custom font in www directory: e.g. IndieFlower.ttf from here
Follow the steps from here
This leads to the following upper part of the app.R file:
dir.create('~/.fonts')
file.copy("www/IndieFlower.ttf", "~/.fonts")
system('fc-cache -f ~/.fonts')
Since Linux looks into the .fonts directory to search fonts, you don't need the extrafont package, but you can directly use those fonts like:
ggplot(mapping=aes(x=seq(1,10,.1), y=seq(1,10,.1))) +
geom_line(position="jitter", color="red", size=2) + theme_bw() +
theme(text=element_text(size = 16, family = "IndieFlower"))
This is the answer I received from RStudio regarding this. I haven't tested this out myself.
Hi,
Our developer was able to advise this is due to a possibly unfortunate design choice made when they created extrafont and the associated extrafontdb package. The extrafont font database is stored in the extrafontdb package directory -- that's essentially all that the extrafontdb package is used for.
This means that the extrafontdb directory needs to be user-writable. If the user installs the package, this will work fine, but if root installs the package (as is the case on shinyapps.io), then it won't work.
One potential workaround is to install the extrafontdb package to library that is in subdirectory of the app.
To do it: create an r-lib/ subdir, and download the extrafontdb source package there:
dir.create('r-lib')
download.file('https://cran.r-project.org/src/contrib/extrafontdb_1.0.tar.gz','r-lib/extrafontdb_1.0.tar.gz')
When deployed, the app will include this r-lib/ subdirectory and the extrafontdb source package.
Then, at the top of the app, install the extrafontdb package from the source package, into the r-lib directory.
.libPaths(c('r-lib', .libPaths()))
install.packages('r-lib/extrafontdb_1.0.tar.gz',type = 'source',repos = NULL)
They deployed an app on shinyapps.io that does the extrafontdb installation, and it works fine. The libpath is set so so that install.packages() will install from the provided source package to the r-lib/ subdirectory of the app.
Please let us know if you're able to implement the above or have any additional questions.
Thanks,
Adding an alternative answer to symbolrush's answer which I found did not work. Here was the code I used initially:
# Add fonts to shiny linux server
if (Sys.info()[['sysname']] == 'Linux') {
dir.create('~/.fonts')
fonts = c(
"www/IBMPlexSans-Regular.ttf",
"www/IBMPlexSans-Bold.ttf",
"www/IBMPlexSans-Medium.ttf"
)
file.copy(fonts, "~/.fonts")
system('fc-cache -f ~/.fonts')
}
# Load fonts and set theme
font_paths("fonts")
font_add("IBMPlexSans", regular = "IBMPlexSans-Regular.ttf")
font_add("IBMPlexSans-Bold", regular = "IBMPlexSans-Bold.ttf")
font_add("IBMPlexSans-Medium", regular = "IBMPlexSans-Medium.ttf")
showtext_auto()
The bizarre thing is that the first instance of the app on shinyapps.io worked, including the custom fonts. However when the app went to sleep and was opened a second time, I get this error in the log:
Error in value[[3L]](cond) : font file not found for 'regular' type
I was never able to debug why this was the case, but I tried a simpler solution that has worked perfectly so far. I moved my fonts to a /font folder in the app folder (I don't think using the /www folder is necessary) and added the /font folder using path_folder():
library(showtext)
# Load fonts and set theme
font_paths("fonts")
font_add("IBMPlexSans", regular = "IBMPlexSans-Regular.ttf")
font_add("IBMPlexSans-Bold", regular = "IBMPlexSans-Bold.ttf")
font_add("IBMPlexSans-Medium", regular = "IBMPlexSans-Medium.ttf")
showtext_auto()
I hope this helps anyone who is having problems with their app not running after the first instance, as I could not find the same situation anywhere on stackoverflow.
I have to setup some unit tests to run on UWP. The unit tests work with files on disk. The files location is configured as a full path (C:\Temp\ for example).
I created a unit test application in Visual Studio 2015, in application manifest I checked Internet (Client), Private Networks and Removable Storage. I also setup a file association for my file type (.dat).
When I run the tests I get Access Denied exceptions when the tests try to open the files on disk. The files are opened using the FileStream class.
Exception Message: Test method UnitTests.TestMethod1 threw exception:
System.UnauthorizedAccessException: Access to the path 'C:\Temp\file.dat' is denied.
How can I setup the test application to be able to open arbitrary files on disk?
Update:
This is a sample test:
public class UnitTest1
{
[TestMethod]
public void TestMethod1()
{
// 1. Open the file using a FileStream
FileStream fs = new FileStream("C:\\Temp\\file.dat", FileMode.Open, FileAccess.Read, FileShare.Read);
// or
// 2. Open the file using UWP file API
Task<Stream> ts = GetStream();
Stream s = ts.Result;
}
async private Task<Stream> GetStream()
{
Windows.Storage.StorageFile sf = await Windows.Storage.StorageFile.GetFileFromPathAsync("C:\\Temp\\file.dat");
Stream s = await sf.OpenStreamForReadAsync();
return s;
}
}
At this moment, after further study, I believe it is not possible to open programmatically arbitrary files on disk from an UWP (test) application, you have to use a file picker to select a file and then open it.
I assume you need a fixed sample of pictures to test your app. I would try to add these samples to lets say Assets folder of your unit test app. Then for every sample file in the Assets folder you want use for testing set the properties such that
Build actions = "Content". This will add the file to the App directory after the build. Then you can access your files like this:
StorageFolder assets = await Package.Current.InstalledLocation.GetFolderAsync("Assets");
StorageFile myTestFile = await assets.GetFileAsync("file1.jpeg");
This in fact ensures, that the test samples are always in the sandbox of your application.
Of course, if you are testing some kind of processing, you can first copy your files from the Assets to the root folder of the App in the [TestInitialize] method and after finishing the tests delete them in [TestFinalize] section. I am using this approach for testing some DB operations on SQLite database (which I move from Assets to root as a file and after the test I delete it). It works for me (VS 2017 UWP app) so it should for you too.
You can run your test once. Then got to Settings|Apps & Features and find your UnitTest project on the test machine. Then grant file permissions there.
This is not ideal, because it is not practical on a Build server.
A WebJob running on Azure does not seem to drop the <Content> files (Copy if Newer) into the correct directory.
I get the following error:
System.IO.DirectoryNotFoundException: Could not find a part of the path 'D:\local\Temp\jobs\continuous\LongTasks\lprysn1r.tsv\Content\File.cshtml
And I try to access that file as such:
File.ReadAllText("Content/File.cshtml");
When running locally, it works just fine.
Is there a way to get this static file dropped appropriately?
After doing some tests, the convention is they do a shallow copy of the /bin/Release folder to App_Data/jobs/continuous/LongTasks/
Which means, if there are any folders, they are not being copied.
Moving the "File.cshtml" to the root directory fixes this problem.
I know this is not fully related to the Azure WebJobs SDK, but this is happening on 6/22/2015 with version 1.0.0.
You should use WEBJOBS_PATH environment variable for currently running webjob.
var webjobPath = Environment.GetEnvironmentVariable("WEBJOBS_PATH");
if (string.IsNullOrWhiteSpace(webjobPath))
{
// Handle dev environment
webjobPath = Path.GetDirectoryName(Assembly.GetExecutingAssembly().Location);
}
This will return some path like D:\local\Temp\jobs\triggered\\xxeeeexxx.qzx\, which contains your content files and folders.
I'm trying to upload a file using PHP. My HTML page with the form is stored at
C:\wamp\www\myproject\upload.html
PHP page is
C:\wamp\www\myproject\upload.php,
and the file I'm trying to upload is
C:\wamp\www\myproject\openoffice.txt.
When I try to upload the file, I get the following error:
Warning: move_uploaded_file(/uploads/openoffice.txt) [function.move-uploaded-file]: failed to open stream: No such file or
directory in C:\wamp\www\myproject\upload.php on line 40
Warning: move_uploaded_file() [function.move-uploaded-file]: Unable to move 'C:\wamp\tmp\phpF66A.tmp' to '/uploads/openoffice.txt'
in C:\wamp\www\myproject\upload.php on line 40 Problem: could not move
file to destination directory
Here are lines 40-43 of upload.php:
if (!move_uploaded_file($_FILES['userfile']['tmp_name'], $upfile)) {
echo 'Problem: could not move file to destination directory';
exit;
}
The fact that it's looking in upload.php instead of the folder that it's in makes me wonder whether it's a server error or an issue with my PHP.
I Googled and got this advice but I don't know if it's the right advice, or how to implement it. Help?
You should be supplying a file system path for $upFile, not a web based path. try using the full system path to you your uploads directory like C:\path\to\uploads\openoffice.txt. Unless of course youre actually trying to place the file in C:\uploads...
Try this code
$imgName = time();
$imgPath = BASEPATH."../uploads/".$imgName;
$image = base_url().'uploads/'.$imgName;
move_uploaded_file($_FILES["file"]["tmp_name"],$imgPath.".jpg");
$imageNew =$imgName;
Where uploads is the folder name just rename it with your folder name or make your folder as name it as uploads. Its working code.
Thanks
Give your '/uploads/' folder where you are going to upload your file. 777 rights. Give full permission to that directory.