How to get all posted files at once using fineUploader? - fine-uploader

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.

Related

Is there anyway I could count the visitors for a specific file in the public folder?

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.

How to upload multiple file in one form

Interface
I have a few file upload, then how to upload all the file only for input that have files.
DO i need to upload one by one or push all in one array, then save the data using the array.
any suggestion ?

Firebase functions callable - image as argument

I have a firebase function which given some arguments creates a "post" with a title and the such. Is there a way to send an image as an argument which can then be processed by firebase functions and then upload to firebase storage.
I think it is possible by decoding the file/image object to a base64 string which could be then sent as an argument. How would I convert the file object from html file input to base64? On the other side how would firebase functions know that the string is an actual image? How can I tell the size of the image? Is there a limit to the size of arguments given to a firebase callable function?
I ditched this question but came across the problem later in a different project. So to anyone seeing it is possible through base 64 strings. It has the restraints that the image cannot be bigger than 10mb but it is easier than trying to "catch" the file after it being uploaded directly.
Here is the solution
I would do the following:
Let the user upload the file directly into firebase storage in a folder where only the user has access to.
Let a function trigger on upload that takes this image, checks if the user is authorized to put that in the target folder and put the file in there (or whatever you want the function to do exactly).

Uploading files to a web service into multiple folders using Jmeter

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

Using an output file stored on the OpenCPU server as input to a subsequent function call

Question: how can I use an output file stored on the OpenCPU server as input to another function?
Background:
I am attempting to use knitr and markdown within openCPU to generate html that I can use to update a webpage with statistical information on the page load.
The basic workflow is as follows:
Generate an .Rmd file, store locally.
Access a webpage that uses AJAX to upload the .Rmd file to an OpenCPU instance on the server.
Use the knit function via openCPU to turn the function into a *.md file stored on the server.
Use the markdownToHTML function on the file stored on the server (by passing in the appropriate hash generated via the call to knit) and receive an AJAX reply that contains the generated HTML.
Update web page with new HTML.
As it stands, I have this process working up to step 4. I can call knit passing in an .Rmd file via a form request POST, and I receive the following reply from OpenCPU:
{
"object" : "xa9eaea44e1",
"graphs" : [
"xf31dcfe7f3"
],
"files" : {
"figure" : "xfc55396fd8",
"test.md" : "x7821c69f79"
}
}
where "test.md" is the output file generated via the knit function. Now, I attempt to use the hash (in this case "x7821c69f79" by POSTing to /R/pub/markdown/markdownToHTML/ascii with the following parameters:
file /R/tmp/x7821c69f79/bin
This returns an HTTP 400 error with the following message:
cannot open URL 'http://localhost/R/store/R/tmp/x7821c69f79/bin/rds'
However, when I make a GET request to /R/tmp/x7821c69f79/bin, the contents of test.md are returned. So I know the file is being stored correctly on the call to knit.
So, what's going on here? In other words, how can I use an output file stored on the OpenCPU server as input to another function?
Hmz the /store error looks like a bug, I'll look into that.
Maybe in step 3 you can have the function return the contents of test.md, e.g. end with return(readLines(test.md))? Or better yet, don't output to test.md but to a tmpfile() and return the contents of that. This way the output is stored as an R object in the store, rather than a raw file, and you can just pass an argument e.g. file=x7821c69f79 in step 4.
Did you have a look at the markdown example app? See source here and here.

Resources