I'm working on a back-end feature that involves processing CSV files uploaded by users. Most tutorials I've found so far suggest that I should read that CSV file through a multipart request.
https://www.appcoda.com/restful-api-tutorial-how-to-upload-files-to-server/
How does HTTP file upload work?
However, as far as I know, multipart requests involve a boundary and only make sense when we need to send different kinds of payload over the same request. For CSV file uploading, all I need is to send a byte stream over the request body (with the appropriate text/csv content type).
I'm not sure if there is any specific reason that people use and suggest multipart requests for uploading files?
if you use text/csv your request body should be raw text (like with json) like
"1,2,3
4,5,6"
But if you want upload file, content-type should say about it.
so, in that case i recomend to use multipart/form-data when uploading any type of files
How does Chrome determine the name of the file being saved to disk when downloading a file?
Whenever I download a file from a particular website I am working on (as a developer), Chrome is appending an underscore to the end of the file extension. (See: Chrome on Windows adding trailing underscores to downloaded files? ). I've been playing around with various content-type and content-disposition headers, and it appears that Chrome is ignoring the filename specified in the Content-Disposition header. For example, if I make a request to download a file, and the response comes back with the following headers (among others):
Content-Disposition: attachment;filename="example.pdf"
Content-Type: application/pdf
... the name of the file saved to disk is still the original file name. In this example, the original file is named test.pdf, and rather than saving it as example.pdf (as specified in Content-Disposition), it is being saved to disk as test.pdf. This seems to hold true for any sort of file type - even something as simple as a .txt file. There doesn't appear to be any other HTTP response headers dictating the file name.
Is there something special that Chrome does to determine the name of the file being saved to disk? If so, is it possible to override this behavior?
I understand that Chrome will rename certain downloaded files that it sees as a security risk (e.g.: renaming .lnk to .download), but even in a case like this, it is still ignoring my Content-Disposition headers for safe file types.
I'm new to Jmeter and am trying to use variables from a CSV file in the path of my HTTP GET request.
I've looked through various tutorials and answers to this question, but I still can't figure out what I'm doing wrong. The file just has one header (ID). It works if I enter the ID in the path, but as soon as I try read it from the CSV file, it fails:
Your configuration looks good, double check jmeter.log file for any suspicious entries.
Other recommendations:
Given you have only a single column it might be easier to use __StringFromFile() function directly in the HTTP Request sampler body like:
/api/Users/${__StringFromFile(c:\Automation\Test.csv,,,)}
I believe Content-Type and Authorization should go in HTTP Header Manager, not in the request parameters
See Testing SOAP/REST Web Services Using JMeter article for more details.
The problem wasn't with the reading of the variable. I thought that the first line of the file would be treated as a header, but it reads the first line of the file as a variable, so my file looked like:
ID
001
It read "ID", when I wanted it read "001.
I have a link which points to a CSV file. When clicked, it opens the file in the browser. I would like to use a different application (i.e. Excel, Open Office, Lotus) to open the file as a spreadsheet. Is it possible to include headers or something to make this happen? Thanks
Link:
<a target="_blank" href="contacts.csv">Contacts</a>
Browser Displays:
First Name,Last Name,Title,Email,Company,Address,City,State,Zipcode,Direct Phone,Mobile Phone,Direct Fax,Company Phone,Company Fax
John,Doe,Estimator,johnd#acme.com,Acme Co.,112 Main St,Gothem,IL,,(847) 555-1122,,,,
Jane,Doe,Engineer,,Ace Industries,,Seattle,WA,,,,,(206) 555-1234,
You will need to set the content type header on whatever generates the csv file.
See: Setting mime type for excel document
For the available headers.
You don't say which language you're using to generate the csv data, or whether it's simply a flat file you're linking to. While most languages will provide the means to set headers on the fly, if you are using static flat files, you may need to set your htaccess (assuming apache is your web server). There are instructions for that case here: http://htaccess.wordpress.com/2008/07/16/sending-correct-content-type-headers-with-htaccess/
The answer that #stakolee links to is really more specific to opening a file in Excel. If you want to be correct and widely compatible, the mime type should be for CSV, not Excel.
The correct mime type is text/csv. Excel will likely be the application associated with this type, so you'll get the behavior you want.
What MIME type should I use for CSV?
You cam also set Content-Disposition to help things along.
Content-Disposition: attachment; filename="filename.csv"
What to set as mimetype for CSV files to open in spreadsheet applications
If you want backup options, you can set multiple mime types.
text/csv, application/csv, application/excel, application/vnd.ms-excel, application/vnd.msexcel
Filepicker does not accept mimetype 'text/csv' on windows
RFC 4180 says you can respond with text/csv; header=present or header=absent to indicate if the files contains column headers.
Proper syntax for optional header parameter for text/csv mimetype?
I have developed a small Java Web Application where a user will upload a XML file. Once the user submits the form, the XML file is converted into an html file using XSLT and saved on the file system. Now I want to send this file back to the client/user as a response. How can I do that ?
Read the bytes of the file, and send them to the HTTP response's output stream. You should also set the content type to text/html, and the content length to the length of the file.