Nightwatch File Upload Validation - file-upload

I tried to compare the file upload to the data in database.
How to validate the file upload content to the data in database or User Interface in Nightwatch?

Related

How to load images/videos directly from server in Blazor WebAssembly?

I implemented a solution in Blazor webassembly that allows the user to upload an image and store the file on the server and the filepath in the database. When I load the image on client I send the image from the sever to client as bytes and transform the image bytes in a base64 string and display the image. This works well but from what I read, this is not a good practice because the base64 tranformation is increasing the file size by 30% and the images cannot be cached on client. I would want to let the browser download the file from the server path and display the image. My questions are the following:
How do I set the server 'root' location in order for the browser to know where to get the files ? I'm using IWebHostEnvironment on the server to get the local path.
Is there any way to secure the files to allow only the authorised user to download the files from the server ?
Should I add the images in the same folder as the solution or I should make a different folder outside of the solution ?
I'm currently using IIS Server with ASP.NET CORE 5 in a Blazor WebAssembly solution.
EDIT 1:
Controller method:
[HttpGet(API.GetFile)]
public async Task<FileContentResult> GetFile([FromQuery] string fileType,string encoding,string name)
{
var path = Path.Combine(_webHost.ContentRootPath, "Media", "Images", name);
byte[] file = await System.IO.File.ReadAllBytesAsync(path);
return File(file, encoding);
}
Link used to access the file :
https://localhost:44339/GetFile?encoding=image/jpeg&name=3020_1_21.JPEG
Generated tag in the browser:
<img style="width:300px;height:300px" src="https://localhost:44339/GetFile?encoding=image/jpeg&name=3020_1_21.JPEG">
As I mentioned in comments, the link works in Postman, it retrives the image, but it does not work in the browser, there is no file retrieved.

How to upload pdf to S3 bucket?

I recorded jmeter script with blazemeter to upload a pdf file to the s3 bucket.When I parameterize the required values and execute the script to upload the file I am getting the error response
Response code: 403
Response message: Forbidden
All the parameters have correct values passed.
You should also get an appropriate Error Code which provides way more information regarding what's wrong, i.e. Access Denied or All access to this Amazon S3 resource has been disabled., once you know the root cause you should be able to figure out what needs to be done in order to resolve the issue.
Also double check all the request parameters using Debug Sampler and View Results Tree listener, for example you cannot record and replay X-Amz-Signature, you need to generate a proper one for each and every request, see How to Handle Dynamic AWS SigV4 in JMeter for API Testing article for more details

Azure File Storage the server responded with a status of 400 (Condition headers are not supported.)

I have some png files stored in Azure file Storage, and I'm retrieving and displaying it from my MVC web project to the browser. But sometimes I get the below error message from browser console.
Failed to load resource: the server responded with a status of 400
(Condition headers are not supported.)
If I refresh the page again, the error message disappears automatically. But it doesn't solve my problem as I run my MVC project again, the same error comes back. How to solve it?
It's acutally a common issue on Azure Storage, which be listed in the offical reference Common REST API Error Codes as the figure below.
It means that Get File REST API does not support those request headers which not be listed in the Request Headers.
There is a similar SO thread Azure File Storage Error: Condition Headers Are Not Supported, which got the same issue with yours. It seems to show up different behavior in different browses when you get a file from Azure File Storage.
I could not reproduce this issus by a file url with SAS token, but I really recommend that you need to store these static files like images on Azure Blob Storage, as I known and as Azure best practice, to show an image by its url with sas token or a public container.

Differentiating Application Upload and FTP Client uploads

Assume we have an web application where user will be provided an option to upload folder/file
Assume we have created an IAM and configured FTP to access S3 via FTP.
Now the user can upload a folder/file via FTP or web application.
We need to create a event notification or call a rest api whenever a new folder or file has been uploaded.
How to register an event register and call the rest API whenever a new folder or file has been uploaded?
How to differentiate whether the upload or file has been done from web application or FTP server from S3 ?
We need to call a different api when the folder has been created via web application and we need to call a different api when the folder has been created via FTP server
Thanks.
1) You can register to an object created event using lambda function via the properties of the bucket(ObjectCreated(All) event), and then execute a call to your API.
2) You can add a metadata to you file while uploading it saving the source of the upload. For example in your http request add the following header x-amz-meta-filesource. Every header starting with x-amz-meta- will be saved as the file metadata.

WebApi json to csv client download

I need my application to hit the database, build up a list of my objects, format as csv string then return back to client javascript for client to download as a csv file.
Can this be done with MVC4 webapi controllers? Client is using IE8 so the method creating my own CsvFormatter class inheriting the MediaTypeFormatter then building up string and letting user save client side with the following is not possible as IE8 doesn't support the Download attribute.......
Any help appreciated.