I have a DjangoRest/ Vue.js app.
I have endpoints where I upload users pictures.
In production my urls were : "picture": "http://127.0.0.1:8000/media/image.jpg"
Now with my app deployed on Heroku it's: "picture": "https://myapp.herokuapp.com/media/image.jpg",
But as I try to GET an uploaded picture, I get a
Not Found The requested resource was not found on this server.
In my settings.py I have:
MEDIA_ROOT = os.path.join(BASE_DIR, '..', 'uploaded_media')
MEDIA_URL = '/media/'
And in my urls.py:
urlpatterrns[] + static(settings.MEDIA_URL, document_root=settings.MEDIA_ROOT)
What am I missing?
Related
I'm trying out the new Strapi v4. I installed the provider-upload-aws-s3 to upload my images to S3 and configured it. I do see my images in the S3 bucket, but I do not see them in the Media Gallery. I inspected request and I see I'm getting this error:
Content Security Policy: The page’s settings blocked the loading of a resource at {my img URL}.
When trying to get the image directly in the browser with the same URL and the image is being loaded.
I believe it has something to do with this warning (quote from Strapi documentation):
Strapi has a default Security Middleware that has a very strict contentSecurityPolicy that limits loading images and media to "'self'" only, see the example configuration on the provider page or take a look at our middleare documentation for more information.
But I'm not sure what to do with it and how to override it. So how do I make the uploaded to S3 images appear in the Media Gallery?
Well, at this point I was really sure it's a bug and reported it at Strapi Github issues. But according to this answer I received some more configuration had to be done in middlewares.js file:
module.exports = [
"strapi::errors",
{
name: "strapi::security",
config: {
contentSecurityPolicy: {
useDefaults: true,
directives: {
"connect-src": ["'self'", "https:"],
"img-src": [
"'self'",
"data:",
"blob:",
"your-s3-url",
],
"media-src": ["'self'", "data:", "blob:"],
upgradeInsecureRequests: null,
},
},
},
},
"strapi::cors",
"strapi::poweredBy",
"strapi::logger",
"strapi::query",
"strapi::body",
"strapi::favicon",
"strapi::public",
];
I changed your-s3-url to *.amazonaws.com and then everything finally worked.
Hi i try connect my page in netlify with a service external but i dont now how configurate _redirects I put this:
/api/* http://www.webservice.com/:splat 200
And my app get webservice and put these url https://myapp.netlify.app/api/products
i want that put http://www.webservice.com/api/products
my _redirects is in public folder , my app is developer in react-hooks with webpack
plese someone cant help me,
Put the following in your netlify.toml file:
[[redirects]]
from = "/api/*"
to = "http://www.webservice.com/api/:splat"
status = 200
Then browse to https://myapp.netlify.app/api/products and it'll show you the page at http://www.webservice.com/api/products.
I am surprised, after successful deployment of a Django web application on heroku server.
I am able to view the media files just after the deployment but after sometimes i am unable to view it.
Error : GET https://mysite.herokuapp.com/media/files/testing_pphTYTV.mp4 404 (Not Found)
suggestions to resolve this is appreciated.....
i have used following line of code.
In settings.py file:
MEDIA_ROOT = os.path.join(BASE_DIR, 'media')
MEDIA_URL = '/media/'
I have a decoupled application in which the frontend is in Vuejs (SPA) and the REST backend in Python/Django.
For cost reasons, I would like to deploy both of them in the same Heroku app. Is it possible?
I've been reading about the Procfile but I'm not sure it allow me achieve it.
Thanks
Just serve the static files from django.
For example, in your vue.config.js:
module.exports = {
publicPath: '/',
outputDir: "dist",
assetsDir: "static",
indexPath: "spa.html",
css: {extract: false}
}
In django urls.py:
urlpatterns = [
re_path(r'^app/*', TemplateView.as_view(
template_name='spa.html',
extra_context=SPA_CONTEXT,
)),
]
And remember to add the static assets and template folders in your settings.py.
Yes, it is very much possible.
I found some documented help by a simple google search. You can refer to these links -
https://elements.heroku.com/buttons/gtalarico/django-vue-template
https://elements.heroku.com/buttons/gtalarico/flask-vuejs-template
I have a problem when using cloudinary in codeigniter. At first, i integrate the library by following answers from
Upload image to Cloudinary using PHP Codeigniter
It worked when i uploaded online image. But failed when i tried to upload local image. The error is
Error in loading http://localhost/admin-simple/assets/img/avatar1_small.jpg - 503 Service Unavailable
Here is my code :
Cloudinary::config(array( "cloud_name" => "my_cloud_name", "api_key" => "1234", "api_secret" => "ABCD" ));
$data['upload'] = \Cloudinary\Uploader::upload("http://localhost/admin-simple/assets/img/avatar1_small.jpg");
$this->load->view('partials/sukses_upload_gambar',$data);
Can anyone help me ? Because i've been stuck for hours. Thanks.
According to Cloudinary documentation, when uploading a file from your computer, you should specify the filepath instead of the URL of your local server:
\Cloudinary\Uploader::upload("/home/my_image.jpg")
http://cloudinary.com/documentation/php_integration