Server is returning cached file - flask

I am creating the following anchor tag dynamically, to download the file I receive from flask backend. The url in a.href is always constant. But the content of output.mp4 keeps on changing.
However, the content of file I get on a.click() is not changing. The file I get is the one I created atleast 3-4 hours ago. How do I get the updated file, on each a.click() call?
var a = document.createElement('a')
a.href = 'http://localhost:5000/download/output'
a.setAttribute('download', 'output.mp4')
a.click()

This is almost 100% to do with the cache setup on the backend.
A simple solution would be to append a cache breaking flag on the output, such as
a.setAttribute('download', 'output.mp4?cachebuster=' + Date.now())

Related

Django Request input from User

I'm having a Django stack process issue and am wondering if there's a way to request user input.
To start with, the user is loading Sample data (Oxygen, CHL, Nutrients, etc.) which typically comes from an excel file. The user clicks on a button indicating what type of sample is being loaded on the webpage and gets a dialog to choose the file to load. The webpage passes the file to python via VueJS/Django where python passes the file down to the appropriate parser to read that specific sample type. The file is processed and sample data is written to a database.
Issues (I.E sample ID is outside an expected range of IDs because it was keyed in wrong when the sample was taken) get passed back to the webpage as well as written to the database to tell the user when something happened:
(E.g "No Bottle exists for sample with ID 495619, expected range is 495169 - 495176" or "356 is an unreasonable salinity, check data for sample 495169"). Maybe there's fifty samples without bottle IDs because the required bottle file wasn't loaded before the sample data. Generally you have one big 10L bottle with water in it, the ocean depth (pressure) and bottle ID where the bottle was closed is in a bottle file, and samples are placed into different vials with that bottle's unique id and the vials are run thought different machines and tests to produce the sample files.
My issue occurs when the user picks a file that contains data that has already been loaded. If the filename matches the existing file data was loaded from I clear data associated with that file and reload the database with the new data, sometimes data is spread over several files that were already loaded and uploader will merge all the files, including some that weren't uploaded, together.
A protocol for uploading data is for the uploader to append/prepend their initials onto a copy of a file if corrections were made and not to modify the original file; a chain of custody. Sometimes a file can be modified by multiple people and each person will create a copy and append/prepend their initials so people will know who all touched the data. (I don't make the rules I just work with what I have)
So we get all the way back to the parser and it's discovered the data already exists (for a given sample ID), but the filename is different. At this point I want to ask the user, do you want to reload all the data loaded from the other file, update existing data with the new file or ignore existing data and only append new data.
Is there a way for Django to make a request to the webpage to ask the user how it should handle this data without having to terminate the current request? - which the webpage is waiting for a response from the server to say the data was loaded and what errors with the data might have been found -
My current thoughts are to:
Ask the user before every file upload how a collision should be handled, if it happens
Or
Abort the data load, pass an error with a code back to the webpage, the error code indicates to the webpage that the user has to decide what to do. Upon the user answering, the load process is restarted with the same file, but with a flag to tell the parser what to do when the issue is eventually encountered again.
Nothing is written to the database until a whole file is read so no problem aborting the process and restarting if the parser doesn't know what to do, but I feel like there might be a better way.

JMeter extract 500 errors from list of URLs and output them in a csv file

I'm running JMeter 5.4 (via Jenkins) to work through a long list of URLs (from a .txt file) in order to check that they have a 200/301 Status Code.
When I run the test, some of them fail, so what I'd like to do is somehow extract any URLs that have a 500 status code, and then output these (just the 500 status code URLs) to a separate csv file so I can easily see what URLs fail.
I would also like to be able to view this (500 failure) new csv file in Jenkins (I have the performance module up and running), but think I'll try and walk before I run! :)
Is this possible, and if so how would I go about extracting 500 status code URLs in JMeter?
Any help would be greatly appreciated.
You can use a Listener like Simple Data Writer in order to store the failed requests URLs into a file, example configuration for Simple Data Writer:
You can use a JSR223Post processor to write the URLs to a CSV file.
Add a JSR223_PostProcessor to your HTTP Request as a child element
Inside the script area check the response code (=='500') and write the URL
println("Before checking the response code ")
if (prev.getResponseCode().equalsIgnoreCase("500")) {
//print
println("Start writing to file ")
FileWriter fstream = new FileWriter("failed-urls.csv",true);
fstream.write(vars.get('URL')+"\n");
fstream.close();
}
Methods available from the previous sample result (prev variable) can be found in API documentation.
JSR223 Post Processor need to be places as a child element to the HTTP Request

HttpQueryInfo to get File Size

Why does this function work on a direct url to a download however fail on a php page echoing out a file for download? (GetLastError is 0)
Not all HTTP requests will have a content length field in the response. Dynamic pages generated by PHP scripts might not know how large the content actually is.
In these cases you need just need to read a little bit at the time until there is no more data returned from the server.

Uploading files with classic ASP - Cant do larger than 120 KB?

This is driving me crazy. We recently migrated over to Amazons EC2 service, and now file uploads (using Motobit Huge ASP Upload) in our application fail for any files larger than 120kb. I know the default limit is 200kb, but its failing for anything larger than 120 with an error number of -2147024893 (0x80070003) with no description/details at all. I cannot find anything in the event viewer or IIS logs to help point me in any direction.
I did go into IIS under the ASP properties for the site in question, and changed the Maximum Requesting Entity Body Limit from 200000 to 400000, and it made no difference at all. I even tried an iisreset, as well as rebooted the server after making the change just to ensure it applied out of hopeless desperation.
I have tried a multitude of different files and file sizes. The most I have been able to upload is a 120KB file. Its not a code issue, as this same code is working on my local box (IIS 7) without issue, and was simply copied over from our old server as-is.
EDIT: I have also tried the following with no results:
set the request filtering settings of Maximum allowed content length to 30000000 (30 Mb).
Manually edited web.config and added requestLimits maxAllowedContentLength="15728640" and httpRuntime maxRequestLength="2147483647"
I hope this can help someone in the future, because I was banging my head against my desk trying to resolve this.
This component has a maximum memory setting of 128K. Any files that are larger than this are not stored in memory, but instead stored in the temp folder. The default temp folder is C:\Windows\Temp.
The culprit was an Application Pool Setting, under advanced settings. 'Load User Profile' was set to true. Resulting in the component trying to use a temp path in C:\Users, which was failing. There are 3 solutions:
Set Load User Profile = False
Assign a temp folder in code (Form.TempPath = "")
Create the folder in C:\Users (use response.write form.CheckRequirements)
For our case, #1 was the perfect solution. #2 would have required edited over 100 files, and #3 would only be needed if you are required to have #1 set to true.

opencart: I can edit order but cannot delete it. (with Error log)

I use opencart version 2.1.0.1
Everytime I click admin > sales > order, it will pop up "error undefined." By closing that popup window, I can still edit order but cannot delete order (no response).
In my log, there is:
PHP Notice: Undefined variable: order_id in
/var/www/html/opencart2101/system/storage/modification/admin/view/template/sale/order_list.tpl on line 821
The line 821 is:
url: 'index.php?route=extension/openbay/addorderinfo&token=<?php echo $token; ?>&order_id=<?php echo $order_id; ?>&status_id=' + status_id,
However, I haven't installed any openbay related module. Also, line 821 is inside <!-- --> mark. It should have no effect.
Help!
Although this is now an older version of opencart, I still see this being reported a lot around and about.
The problem occurs due to the store front adding the http url rather than the https url to the order. So firstly you need to fix that. If you dont want to read all of my explanation, you can just hit up the bold points :)
Either way BACKUP EVERYTHING actually not really, back up the file you are going to edit and backup your whole database.
open:
catalog/controller/checkout/confirm.php at around line 100
Find:
$order_data['store_url'] = HTTP_SERVER;
Change to:
$order_data['store_url'] = HTTPS_SERVER;
Now you will want to fix your database because for reasons I cannot fathom, the domain name is placed in the order along with the stores id. and when editing orders it is the usage of that directly within your admin order page that throws up the undefined notice. Basically the browser blocks the request because its trying to make an insecure request from a secure page.
Crack open phpmyadmin or whatever database tool you have on hand.
locate the table, default is oc_orders
Browsing the table, look for the column that contains your store url (i cant remember the name off hand, i think its just store_url but it will be obvious anyway. if you are multi store you will need to run the query for each
I am sure somebody can come up with a clever way to automatically convert just the http into https with a single use sql query on the one column, but this works for me.
Run SQL: adjust as appropriate
UPDATE `oc_orders` SET `store_url` = 'https://example.com' WHERE store_id = 0;