Set the destination path for an uploaded image in a flask app - python-3.x

I have made an application in flask which asks the user to upload an image, that image is being stored in a folder inside the static folder. I have specified the full local path in the code when I run that application locally to store that image. I want to deploy this application on IBM cloud. So, I can't write the path that I had set on my local machine. Any help what path should I give for the folder where the image is to be uploaded. Thanks in advance.

You want to use absolute paths.
MYDIR = os.path.dirname(__file__)
os.path.join(MYDIR + "/" + app.config['UPLOAD_FOLDER']

Related

Securing files in Google Cloud app engine (NodeJS)

I have created a small web application with NodeJS Express. Basically a webserver that has a 'webserver.properties' file. With a very basic app.yaml file.
After deploying it to Google Cloud by use of 'gcloud app deploy' I get the everything up and running.
However...when I open the following URL in the browser: https://webserverurl.com/webserver.properties , the webserver.properties file can be approached and is in turn downloaded immediately.
How can I prevent this from happening and make sure that such properties files are inaccessible from outside?
The problem is that when you use this line:
app.use('/', express.static(__dirname + '/'));
you are giving access to your root directory. See this for a definition of __dirname. If you want to give access to a specific folder you can do this:
Lets say your root directory is src and you fave a dir with static files called src/myfiles. In order to give acces to files in myfiles you can use this line:
app.use('/mypathname', express.static('myfiles'));
where:
'/mypathname' is the part pertaining your URL. In your case it would be https://webserverurl.com/mypathname/any-file-name.jpg
express.static('myfiles') is the name of your local dir.
See this guide.
Hope this helps

Can't establish the URL of Bot Builder files stored in Azure App Service

I am developing a chatbot using NodeJS and BotBuilder. I have the file chatbot.jpg stored in a folder named image. This sits just beneath the root directory. I am able to display the image (using Kudu to find the URL) in a web browser as follows:
https://mysite.scm.azurewebsites.net/api/vfs/site/wwwroot/images/chatbot.jpg
If I remove the .scm element within the URL, I can no longer display the image.
Even more curiously, if I use the above URL in my bot code, the image doesn't display.
var welcomeCard = new builder.HeroCard(session)
.title("This is the new")
.subtitle('Virtual Assistant')
.images([
new builder.CardImage(session)
.url("http://mysite.scm.azurewebsites.net/api/vfs/site/wwwroot/images/chatbot.jpg")
alt("Virtual Assistant")
]);
session.send(new builder.Message(session)
.addAttachment(welcomeCard));
My question is, how do I find out the regular URL of the image stored in the Azure App Service, so that I can use it in my code?
From the public web, the URL should be https://mysite.azurewebsites.net/images/chatbot.jpg
The wwwroot folder is the root folder served by the app service.
Your code can't just the scm URL as that URL requires you to be logged in to the Azure portal; it's an admin URL.
To accomplish your goal, you need to configure your Restify server to serve static files.
Example Restify config (add to your bot code):
server.get(/\/images\/?.*/, restify.serveStatic({
directory: './images'
}));

Xpages Layout Control - Node Image path

I use Application Layout control (OneUI 3.0.2) with a few Application Links.
The image path is calculated because the images are saved in a separate image application.
The problem is that the Layout Control always add the path of the current application in front of the calculated link.
The only way i found was to calculate the absolute path (with http://..) to avoid this. But for me this is not a good solution, specially when you want to use a reverseproxy in front.
The image path is relative to current database by default.
Add "/.ibmxspres/domino/" in front of your image path to make it relative to Domino server's data directory instead.
Example:
Application path: /apps/hr/hr.nsf
Image database path: /core/images.nsf
<xe:basicLeafNode
...
image="/.ibmxspres/domino/core/images.nsf/yourImage.gif">
In case the image database is in same directory like your application database you can set image's path relative to current database path.
Navigate from application database path back to common directory with /.. and then to your database.
<xe:basicLeafNode
...
image="/../images.nsf/yourImage.gif">

Cant access images one directory back

I am using linux server and I am using absolute path for files which is stored in a "constant"
File path is
/home1/mousi1/public_html/xyz/data/1465221530.png
Image is loading when I access file which is on home directory like
/home1/mousi1/public_html/xyz/file.php
but when I try
/home1/mousi1/public_html/xyz/subdirectory/file.php
Path is still
/home1/mousi1/public_html/xyz/data/1465221530.png
but image is not showing I am wondering why is it?
What is wrong?

How to set the file upload path in liferay portlet so that it can be stored either in unix or windows system(machine independent)?

The suggestions were giving the path as catalina_home or user/home.
Do I need to set any parameters in server.xml?
And using actionRequest.getPortletSession().getPortletContext().getRealPath("/"); I am unable to store the file path in database.
Properties properties=PortalUtil.getPortalProperties();
String serverHome = properties.getProperty("liferay.home");
//To get the liferay server home folder
create any folder for uploaded files under it.

Resources