pyramid static view and file upload - python

I created new directory via 'myimages' under static directory. And whenever user upload files, file get stores in that directory. Once file uploaded I can access that on html using '/static/myimages/imagename.png'. It works fine whenever I am uploading new image. But whenver I try to override image. It shows me old image only.
I manually check in directory. It has new image, but still when I try to access that via browser, it gives me old image.

This sounds like your browser is caching the images. Try setting the cache_max_age=0 on your add_static_view, or viewing the page in your browser's incognito mode where it'll use a different cache.

Related

Unable To Update Image On Google Cloud Storage via API

I am trying to overwrite an image in my Cloud Storage over the Python API, but after I overwrite it and refresh (and delete browsercache) the Cloud Webpage or the public link the image is still the same, even the next day but sometimes it gets randomly updated to the new image!
Edit: The Metadata get updated, but not the filesize-info and it still shows the old image in the Cloud-Webpage and at the public url.
What I am expecting is that if I am uploading a file to Cloud Storage via a API that I can download the new file from the public link a short time afterwards instead of the old image.
I expected to be able to define the cache behaviour with the Cache-Control File-directive (Edit: it is propably not an issue about caching because even the next day the image stays the old one).
This is my code:
blob = bucket.blob(name)
blob.cache_control = "no-store"
blob.upload_from_filename(name)
I tried:
Deleting the old image over the Cloud-Webpage and then after a few
seconds upload the new image with the same name via Python: It works!
I can download the new image from the public link and see it in the
Cloud-Webpage. Edit: It seems to work only some times!
Deleting the Image with Python and directly afterwards upload the new
image via Python: Not working. While it is deleted the public link
doesnt show it. But after I uploaded the new one the public link
shows the old one again.
I read that the standard cache settings of public bucket files is
"public, max-age=3600". So I used the Cache-Control Directive and set
it to "no-store" or "public, age=0". Then I confirmed these
Cache-Control settings are reflected in the headers in the browser
debug console. But still the old image is loading anytime.
I changed the bucket type to regional instead of multi-region. Even after deleting the bucket, recreating it and moving the data inside it again the old image is still showing up!
Any tip is highly appreciated!
I made it work!
It was propably not related to Google Cloud Storage.
But if someone might did the same mistake as I:
I used Django's FilesSystemStorage-Class and saved the new file with the same name as the old one in the /temp directory, assuming that the old one will be overriden if it still exists. But instead it gives the new file another name. And later I upload the old file with blob.upload_from_filename(name)
Thats why all the things happend so randomly.
Thanks to all who thought about solving this!

Change the Directory when Upload a file

I would like to change the default location use by the browser when uploading a file.
I mean I have a website and when the client clic on upload file, I would like to point to a target directory (ie Downloads) instead of Desktop.
How can I do it ?
My website use Flask / Python
That's probably impossible. It's the client who choose's where to save data not the server.
You'll need to know the computer's folders paths. And that's called Hacking wich is illegal.

Is there a way to change the filename of a file, when starting to download a file using Selenium?

I'd like to download multiple files from a single website, but the biggest quirk I have is that the server automatically generates a random filename upon requesting the file to download. The issue here is then I won't know which file is which, without having to manually go through each file. However, on the site that has the links to download the files, they all have a name. For example...
File name -> Resultant file name(fake file names)
Week1.pdf 2asd123e.pdf
Week1_1.jpg dsfgp142.jpg
.
.
Week10.pdf 19fgmo2o.pdf
Week11.pdf 0we5984w.pdf
If I were to download them manually by myself, I would type click "download" and a popup "Save as" menu comes up, which gives me the option to change the file name manually, then click ok to confirm the download, to which it starts downloading.
Currently, my code is made to open up the website, log into my account, go to the files page, and then find a file, with it's corresponding server request link. IE: . I am able to store the name of the file, "Week1.pdf" into a variable, and click on the request link, but the only problem is that the Save as menu, doesn't have the ability to change the name of the filename, and only gives me the option to view the file, or Save the file immediately. I've looked around a little, and tried to play around with the Firefox profile settings, but nothing has worked. How would I go about solving this problem?
Thanks
I can think of a few things that you might try...
After the file is saved, look in the downloads folder for the most recently saved file (with the correct extension) using time stamps. This will probably be OK as long as you aren't running this threaded.
Get the list of files in the download directory, download the file, find the file that doesn't exist in the list of files. Again this should be safe unless you are running this threaded.
Create a new folder, set the download directory to the newly created folder, download the file. It should be the only file in that directory. As far as I know, you can only set the download directory before creating the driver instance.
In each of these cases, if you plan to download multiple files I would rename each file as you download them or move them into some known directory to make it easier on yourself.
There's another method I ran across in another answer.

How to serve non-local images from localhost

I'm writing a Python script that works with images on the user's computer, my plan is to display these images on a webpage via bottle.py (which can change if need be) on localhost. The images and the script could be located anywhere, however serving from localhost doesn't allow me to display images with a file:/// path for security reasons, so I'm stuck as to how I can achieve this. I basically want bottle's static_file function but with multiple files and within a HTML template. Is this at all possible without moving the images?
No, the browser sandbox won't and shouldn't allow this. Think about it this way: if you were able to display images from the user's computer without his explicit approval, they would be part of the DOM and what would stop a script from manipulating them or sending to a server without the user's knowledge?

django pages cms file upload issue with django-storages for s3

Hi All and thank you for taking the time to look at my question.
I'm using django-pages-cms with s3_folder_storage http://pypi.python.org/pypi/django-s3-folder-storage, an extension of django_storages https://bitbucket.org/david/django-storages/.
When I put an img placeholder in my template, the admin displays a file upload as expected. Before I set up my s3 credentials correctly, it also showed a 403 error from s3.
I chose a file in the admin and clicked submit. When the page reloads, it shows that the image has been stored. i.e. it lists a current image file.
However, I can't find the image file anywhere on my server or s3. When I load the page in the browser it points to the correct path on s3, but it can't load it because it doesn't exist.
Does anyone have any ideas as to how I can try to debug this one?
Thanks!
The files were uploaded to a different folder on s3, as set in media root. My mistake!

Categories