Image URL doesn't retrieve image - django

I load an image to my server side in django-admin with ImageField.
My server is deployed to Heroku.
I browse a .png image and search his path, I received it properly.
After couple of minutes, the server doesn't retrieve the image.
In the server logs, I get status 200 or 301, in both cases I don't get the image.
Anyone have any idea to help me find a way to fix this situation?
EDIT:
I find out that it occur because of an IOError after reading the image file.
It is happening with two files from a total of three (the third one is .png and is showing properly and his size is a bit smaller) I think it means, it won't always happend and there is no problem with the path because of it.
EDIT 2:
The way I thought i solved it, didn't worked.
any other idea?

As Fian mentioned in the comments:
There is high chance that there is something wrong with paths. Please
add your MEDIA_URL, MEDIA_ROOT, ImageField code from model and
serializer and image-url that is passed by your server to browser.
What I believe was the problem is, Heroku auto collectstatic to my staticfiles directory.
When I uploaded an image, I had no MEDIA_ROOT and MEDIA_URL settings.
Because of this, every image I uploaded was saved in the BASE_ROOT temporary and I had access to him.
Once in a while Heroku collectstatic my files to my static directory and I lost my connection to those files because of it. I was searching for those files in my BASE_DIR and they have been moved to the staticfiles directory.

Related

DJANGO Static Image deletion

I am experiencing an issue with images saved in the static/images directory in Django. My website was rendering images appropriately, by referencing the name of the image e.g., Image_1. However, once I've tried to delete this image and include a new one in the static/images directory with the same name, Image_1, the website keeps rendering the old image. New images added in the same directory with new names are rendered without issues.
Since then I have specified all STATIC_ROOT, MEDIA and MEDIA_ROOT routes in settings.py, I have run manage.py collectstatic and I have checked the images stored in these directories. The "old" version of Image_1 is not there anymore, but the new one is, and the website still renders the "old" version of it.
Does anybody have an explanation for this, and how to fix it?
Thanks in advance!
Try reset your browser cache "ctrl + f5"
The browser has cached the old image in the PC of browser side .
Close the Page and clear the cache files of the browser,then try again.

Django heroku files

So, I have set up an upload feature in my admin where an admin can upload photos. These photos are accessed via a view such that an admin can use them. I deployed this to heroku. So far it seems to work where if I upload a photo, it gets linked to the view, and it shows up.
My MEDIA_URL ='/media/' and my MEDIA_ROOT = os.path.join(BASE_DIR , 'media') and at the moment, DEBUG = True for my case.
So the problem is this: After leaving the site for a couple of hours or so, when I try to access the files, it seems to have changed the link and the photos are no longer linked.
Is there a way to fix this such that when I leave for some time, the link to the photos do not change? (I don't see a solution based on google, and it seems that people have not run into this problem...unless I'm google crippled :/ )
I realized my issue. They're being uploaded to the media folders that live in Heroku which is not the way to go. instead I used amazon aws s3 to serve both the media files and static files. Here's a link that answered my question:
django heroku media files 404 error
However, I'm thinking of switching to using smartfile because it's free :D

Sitecore - not publishing media library

We are using Sitecore 6.5 and have a multi-site Sitecore solution (with lots of library code we have inherited)
Publishing the Media Library by item from Staging to Production but we are not seeing the image on the web.
The images are in the web database and the path to the images in the web site is good.
Error we are getting when the file is requested (same in browser window address bar) is http://domainname/error?aspxerrorpath=/~/media/OSS/Images/WaterAndWildlife/myimage.jpg.
There is no media prefix in the web.config
Any idea?
....Looking into it now but site is going live tomorrow so help very appreciated! Help!!
We faced a similar problem when, in production, media files were not published which resulted in 404 errors.
Solution: The problem was that media files were not saved to the database because a file path was provided with the Sitecore media files while uploading.
So the images were saved on the file system instead of in the database. But based on our web.config configuration we were fetching images from the database.
If you are facing a similar issue, just download the media image, remove the file path, and save it. Then re-upload the same image, save and publish the image.
Hope your problem will be solved.
One question, are these staging and production environments separate code files? if they are, what is the setting in your web.config for the settigns UploadAsFiles? because if that's true it will store them on server and the images will be on staging but not on prod. But usually if this setting is true and the files are getting stored in file system, specially in CM/CD environment it should push the physical files on publish as well, but sometime there might be other issues going on like permission etc..... and the files cant get to the destination.
"<setting name="Media.UploadAsFiles" value="false">"

Why are the Image paths for django-ckeditor being set incorrectly?

Basically these are my settings.py settings;
MEDIA_ROOT = 'C:/Users/Deep.C/.virtualenvs/projectcontainer/mysite/media/'
MEDIA_URL = '/media/'
CKEDITOR_UPLOAD_PATH = MEDIA_ROOT
Image upload is working within the Rich Text Editor, as the file is turning up in the correct directory.
However when trying to browse images the images are never being loaded due from I assume is the path to the image being incorrect as follows;
<img src="/media/2013\06\25\Google-Chrome-icon_thumb.png">
It is returning a 404 NOT FOUND. In the console the path being displayed http://localhost:8080/media/2013/06/25/Google-Chrome-icon_thumb.png
I know this is a fairly trivial thing probably me not setting things up correctly but i cant seem to figure out where i could have gone wrong.
Any help would be appreciated!
Thanks
Static files and files served from media are done through 2 different methods. In order for the media files to be served you need to serve files from the media folder. To do so follow the guide at https://docs.djangoproject.com/en/dev/howto/static-files/
The section you are interested in is "Serving files uploaded by a user".

Strange django media deployment issue

I managed to deploy cherokee as a reverse proxy for a django app running with cherrypy as information source.
All of the static files and media files seem to be served correctly except for a particular image.
On http://mydomain.com/media/files/none.png, I get a
The image "http://mydomain.com/media/files/none.png" cannot be displayed because it contains errors.
But if I append a ? behind that file's url, it shows up correctly as a 1x1 pixel image.
http://mydomain.com/media/files/none.png?
will give
none.png (PNG Image, 1 x 1 pixels)
which is expected and correct.
Why is this so?
Browser cache problem. Issue solved a while back. Closing this.