Just wanted to know if there is a better way to do this.
I am uploading multiple files to different folders in a web service.
Currently, I have got all the paths for the files being uploaded written in a CSV with their location to where they need to be uploaded to. (This currently works)
The files being uploaded do have a similar name to the location to which it will be sent to e.g. File A to Folder A, File B to Folder B.
Is there a better way in which I can achieve the same thing but in a more file name to match similar folder name without giving the location in a CSV file?
If your filename has a pattern to decide to which server it should upload to,use beanshell preprocessor to finalise the folder name.
For example - File A to be uploaded to Folder A,your preprocessor sample code can be like
String file=vars.get("fileName");//filename variable holds file names
if(file.charAt(file.length()-1)=='A')//checks the whether last char is A
{
vars.put("foldertobeUploaded","Folder A");
}
else
{
vars.put("foldertobeUploaded","Folder B");
}
and use ${foldertobeUploaded} wherever you want to use in sampler.
JMeter comes with If Controller where you can define a condition. If condition is true, If Controller's child(ren) sample(rs) will be executed.
Something like:
If Controller: condition "${someJMeterVariable}".endsWith("A")
HTTP Request to put file into Folder A
If Controller: condition "${someJMeterVariable}".endsWith("B")
HTTP Request to put file into Folder B
etc.
References:
JavaScript String endsWith() Method
How to Use JMeter's 'IF' Controller
Related
I want to pass multiple CSV/JSON files, those contents should be set as POST body data.
How can I achieve this?
If you have those files present in some folder the easiest is to:
Install Directory Listing Config in order to read file names into a JMeter Variable
Use __FileToString() function in order to read the file contents to the request body
Demo:
Currently I'm using laravel, and as you know there are many ways to count the visitors for a single page (hits on routes). But I want also to count the visitors for an image or a pdf file in the public folder, any ideas?
You will need to bypass the route to the file location using a proxy URL from your application. Then serve the files using the proxy URL to access the file.
For example: If you have a pdf file accessible at yourdomain.com/public/some-file.pdf create a proxy URL for the same something like yourdomain.com/proxy/some-file.pdf.
In your routes file create the corresponding route. Note the last part is dynamic and should identify your file.
Route::get('/proxy/{fileName}', [DefaultController::class, 'proxy'])
In your DefaultController.php file do the necessary logging of counts & then serve your original file as a response.
public function proxy($fileName) {
***your logic to increase visit count. db addition or something
$pathToFile = Storage::path($fileName);
return response()->file($pathToFile);
}
One of the possible ways is to have routes that return the stream of pdf/image. That way you can use the same method that you use for pages. It could be through $request->ip or something. The downside is, you have to remake all image/pdf links on your pages to redirect to route instead of asset path or whatever you use.
I have a fineuploader that allows multiple files to be uploaded in MVC web app.
Example:
Suppose I upload 3 files 5MB, 20MB, 1MB
I expect 3 files to arrive in the controller in single call but they are not.
I want to iterate all 3 files (array) and process
Question 1: Is there a way to get all 3 files at once in the server?
[HttpPost]
public FineUploaderResult UploadFile(FineUpload upload)
{
//upload contains only one file at a time
//for second file it gets call again even though I submit only once
}
No. Fine Uploader sends each file in a separate request. This is not currently configurable. If you need to tie your files together, you can easily do that by passing common parameters with each file via the params option, or the setParams API method. Sever-side, you can look for this common parameter in each upload POST request and deal with the files accordingly.
I want to return a .csv file from an ASP.NET MVC 3 ActionResult in the controller. I've found other examples of people doing this out on the web, but it seems like they have an ASP data structure that they are converting to csv.
My situation is a little different. I actually have a file on the local drive called myfile.csv. I want to return the file so the user can download it as a .csv.
Here is my code:
public ActionResult GetCSVFile()
{
return File(service.initiateCsvGeneration(1), "text/csv");
}
initiateCsvGeneration returns a string with a path to the filename. My filename already has the .csv extension and it is already in a comma delimited format. For some reason it is chopping of the .csv extension in my filename. Instead of allowing the user to download it as myfile.csv, it makes them download it as myfile although the actual disk file has the .csv extension and it is also present in the string that is in initiateCsvGeneration.
What else could be wrong here?
You should explicitly specify the desired file name - then your users will be able to see it in download dialog:
return File(service.initiateCsvGeneration(1), "text/csv", "myfile.csv");
I am writing query output to a CSV file in a folder called 'reports_output' inside my 'report_runs' views folder. The file names need to be generated based upon the name given by users running reports and other parameters like current time etc. I have two issues:
How to generate unique file names using Time.now converted to string of numbers (like version numbers in db/migrate) ? and
How to do correct routing to all these .csv files?
I was able to write files with simple names e.g. Item_List.csv below, but not been able to view the files by clicking on the url to the file in my show view in browser. The error says :
No route matches "/report_runs/report_outputs/Item_List.csv"
1: You can generate a filename that includes the current time using simple string interpolation and you can format the string with Time#strftime:
file_name = "item_list#{Time.now.strftime('%Y%m%d%H%M%S')}.csv"
2: If you want to serve static assets like your .csv files then you can write them to the public folder. So for example if you create a file in public/report_runs/report_outputs/Item_List.csv it will be accessible from the path given in your example.
If you generate the CSV on the fly in the controller, then you can route to it like this:
<%= link_to item_list_path(:format => "csv") %>
Assuming that your controller is ItemList.