I deployed my Django project to Pythonanywhere.
my directory structure is as follows.
/home/myappname/myappname.pythonanywhere.com
├── config
├── myapp
├── template
├── static
└── media
└── voices
└── test.mp3
I was able to use google-cloud-to-speech to create MP3 files from text and save them to the following media/voices folder.
/home/myappname/myappname.pythonanywhere.com/media/voices
When I upload an MP3, the address is stored in the model's Filefield.
After that I checked it in the admin site, it is saved in the DB as follows.
/home/myappname/myappname.pythonanywhere.com/media/voices/test.mp3
I could access that MP3 file from Pythonanywhere console. But I could not access it from admin site clicking voice fields.
my browser shows that test.mp3 files address was,
https://www.pythonanywhere.com/user/myappname/files/home/myappname/myappname.pythonanywhere.com/media/voices/test.mp3
I tried a lot to change MEDIA ROOT or MEDIA but I could not resolve my issue.
Current my MEDIA&STATIC ROOT and MEDIA URL settings are,
MEDIA_URL = '/media/'
MEDIA_ROOT = os.path.join(BASE_DIR, 'media')
STATIC_URL = '/static/'
STATIC_ROOT = os.path.join(BASE_DIR, 'static')
STATIC files are fine. My web app could display png image which is located at static folder.
Static files setting
Can anyone give me some advice on this?
The URL you should be trying to access is https://myappname.pythonanywhere.com/media/voices/test.mp3. Whatever is generating the URL that you're trying to access is generating the URL incorrectly.
Related
Goal
I'd like to launch a CLI program closely related to my flutter project, i.e., the program is saved somewhere near the flutter project folder.
My end goal here, is so that I could release a separate problem outside of the flutter app bundle at a fixed location relative to the bundle, e.g., same parent folder, while flutter-built exe can still find the program automatically. The solution targets Windows/macOS.
Expectation
I expect that I could retrieve a standard project path, such as the path to main.dart, and go from there using relative paths. I was so spoiled by Python's __file__ and wish to see something similar. This is also fairly easy to do with Windows/macOS native API, like this
For example, say I created a project under this folder
/path/to/my/flutter_project
I expect to call a Dart API to get the path of main.dart like this
/path/to/my/flutter_project/lib/main.dart
Observation
According to this answer The closest thing I got with flutter, is
import 'dart:io' as io;
Uri filePath = io.Platform.script.resolve('.');
however, puts me to a prescribed location:
// macOS
~/Library/Containers/com.example.flutterRelpath/Data/
This is the package data folder instead of the project folder.
If I query the script itself using
io.Platform.script.path
I get
~/Library/Containers/com.example.flutterRelpath/Data/main.dart
which is not the physical location of the script.
Question
Does it mean that I would need an installer to install the CLI program there or prepare a UI for the user to specify the location before I could use it? This seems a lot of trouble.
There is no reason to obtain the path of the script, nor does that make sense to do in a compiled application as the source files are not directly used at runtime.
You can simply use a relative path to reference whatever file/executable you want.
final uri = Uri.file('relative/file/path');
This will give you a Uri to the path file in the file folder in the relative folder, which would be at the same level as your executable.
├── executable.exe
├── relative
│ └── file
│ └── path//The Uri will refer to HERE
In order for this to be a relative, the passed path must not start with a path separator. So it should not be:
final uri = Uri.file('/relative/file/path');
Have a look at the dcli package and the DartScript and DartProject classes. they have methods designed to provide exactly this type of path information.
E.g.
DartProject.self.pathToProjectRoot
I'm trying to save one of my websites (with all its files) to my pc so i can upload it to another server. I've tried using Httrack and wget but with both I only got a small part of the images and most of it was scattered in a new folder called contentAsset. could someone please help me out?
dotCMS can publish your site statically - set up a static Push Publishing endpoint and then right click and publish your site to it. dotCMS will write out your site and assets statically to a folder under the /assets directory.
I tried MongoDB Stitch earlier this year, and at the time it did not feel like a finished product (for example, apps cannot be renamed). I am giving it another go, and this time I am interested to see how I could create automated tests for my Stitch functions using Jest (this also may not be straightforward).
I have noticed that the Functions section has a DependenciesBeta tab. Here one may zip up NPM modules in a tarball, and they will become available in the Stitch JS environment. I wonder if I could use this to circumvent the import difficulties I am experiencing with the functions system - instead I could make (untested) lightweight calls from Functions to Dependencies, and then just test the dependencies.
However, I want to be able to import my app automatically using the console command, to deploy automatically in a CI pipeline. For this to work, import/export would need to include dependencies as well, but the file-format docs do not mention dependencies. Is there any support for syncing dependencies from the console, as part of an app import?
Is there any support for syncing dependencies from the console, as part of an app import?
Yes, you can import dependencies using mongodb-stitch-cli (v1.10+).
To upload external dependencies:
First need a local node_modules folder containing at least one Node.js package. If the node_modules folder does not already exist, npm install <package> will automatically creates it.
Next you need to package them up in an archive so you can upload them to Stitch:
tar -czf node_modules.tgz node_modules/
Other supported formats/extensions are : .zip, .tar, .gz, .tgz
Next you can place the archive into the functions directory in the application file schema. i.e.
├── functions/
│ └── <function name>/
│ ├── config.json
│ └── source.js
│ └── node_modules.tgz
Execute the import command with --include-dependencies, i.e:
stitch-cli import --app-id <APP_ID> --path ./your_app --include-dependencies
Creating draft for app...
Draft created successfully...
Importing app...
Deploying app...
Deploying app...
Done.
Importing hosting assets...
Done.
Please note that currently stitch-cli does not support export for dependencies yet.
See also Stitch: Upload External Dependencies to upload from the UI.
I have a web application with play framework. All images used in the application are kept in public folder and are accessed with the help of a routing defined in the conf/route file. So all the images I used are present in a jar file after build. But my requirement is that the admin will be placing few images that the UI should be able to access. For obvious reasons I can ask them to add images into the jar.
My plan is to ask the admin to add images to a folder inside the conf folder and read it from there using routing (I believe its possible because currently there is a routing defined that's reading a json from the config file).
# Home page
GET / controllers.Application.index
GET /clientConfig controllers.Application.clientConfiguration
GET /testImg controllers.Application.testImg
# Map static resources from the /public folder to the /assets URL path
GET /assets/*file controllers.Assets.versioned(path="/public", file: Asset)
Being totally new to Play framework I can't figure out a way to define routes for that and read images from a folder inside the conf folder . Any help is highly appreciated.
conf folder is a configuration folder so it's not a good idea to expose it as a public folder. For example from security perspective the application.conf or the database migration files contain sensitive data that shouldn't be accessible on any api endpoint.
What you could do is add an additional root folder to the public managed resources for example create a folder called publicImages in the root folder and add the following line to build.sbt
unmanagedResourceDirectories in Assets += baseDirectory.value / "publicImages"
Also remember that adding images to a folder on the deployed server means you won't be able to cluster, i.e. add additional nodes if/when load grows. So your best option is to use some 3rd party storage service, e.g. amazon s3 (it's pretty simple for the admin to upload images to a folder on s3)
If however you insist on adding the images to conf folder, what you could do is create a standard controller that accepts file name in its parameters (path) and stream the content of that file from the conf folder using
Play.getFile('conf/{myfile}') just make sure to enforce some security constraints like verifying no path is provided so malicious user can't traverse the machine's file system. And support only predefined 'safe' file types like images.
As LiorH said, it's usually not a good idea to expose conf folder to public. But if this is really what you want, then you can try to implement your own controller.
In your route file:
GET /configuration ConfController.loadConf(path)
In ConfController:
def loadConf(path: String) = Action {
Ok.sendFile(Play.getFile("conf$path"))
}
I am trying to automate deployments of a particular project and a bit lost as to who to handle config file as well as user assets.
(Application is based on Zend Framework based btw).
Main application folder is structured as follows:
./app
./config.ini <----- config file
./modules
./controllers
./models
./views
./libs
./public
That config file is where all the configs are stored.
So 'app' folder contains whole bunch of code in PHP and 'public' contains whole bunch of code in JavaScript, HTML/CSS and stuff like that(web accessible basically).
If I follow Capistrano's model, where each package is expanded into it's own folder that is then symlinked to, how do I handle that config.ini file?
What about all the user content that is uploaded into ./public folder?
Thanks!
The Capistrano approach to this is to have a structure like this on your remote server:
releases/
20100901172311/
20101001101232/
[...]
current/ (symlink to current release)
shared/
in the shared directory you include your config file and any user generated content (e.g. shared/files). Then on each deployment, once you've checked out the code you automatically create symlinks from the checkout into your relevant shared directories. E.g.:
releases/20101001101232/public/files -> shared/files
releases/20101001101232/application/configs/config.ini -> shared/config.ini
that way, when a user uploads a file to public/files it is actually being stored in shared/files.